{"modulePath":"github.com/flashcatcloud/flashduty-runner","version":"v0.0.27","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package permission\n\nPackage permission implements glob-based command permission checking.\n\n### Matching semantics {#hdr-Matching_semantics}\n\nRules are evaluated against three normalized projections of every shell command found anywhere in the input — including pipelines, command substitution ($(...) / \\`...\\`), process substitution (\\\u003c(...) / \u003e(...)), arithmetic expansion ($((...))), and redirect targets:\n\n 1. The full normalized command (env-prefix included), e.g. \"KUBECONFIG=x kubectl get pods\".\n 2. The same command with leading variable assignments stripped, e.g. \"kubectl get pods\". This prevents trivial bypass via env prefix and prevents false-deny when a rule lists only the program form.\n 3. Redirect targets are projected as synthetic commands (\"\u003e/path\", \"\u003e\u003e/path\", \"\u0026\u003e/path\", \"\u0026\u003e\u003e/path\", \"\u003e|/path\") so that rules can gate writes the same way they gate executions. Read redirects (\\\u003c, \\\u003c\\\u003c, \\\u003c\\\u003c\\\u003c, \\\u003c\u003e, here-docs) are not checked beyond their inner command (here-doc body and here-string undergo expansion).\n\nBoth rule patterns and the command projections are run through the shell printer's canonical formatter, so \"kubectl  get  pods\" matches the rule \"kubectl get pods\" regardless of spacing.\n\n### Precedence {#hdr-Precedence}\n\nRules are evaluated in specificity order, and the first match wins. Specificity is \"longer literal prefix before any '\\*' wins\"; the catch-all \"\\*\" is always tried last. A deny rule that matches first beats a more general allow rule, and vice-versa.\n\n## Functions\n\n```go\nfunc DefaultRules() map[string]string\n```\nDefaultRules returns a set of default rules that trust model capabilities.\n\n```go\nfunc KubernetesReadOnlyRules() map[string]string\n```\nKubernetesReadOnlyRules returns rules for read-only Kubernetes operations.\n\n```go\nfunc SafeReadOnlyRules() map[string]string\n```\nSafeReadOnlyRules returns rules that allow common read-only operations.\n\nNotably absent compared to a naive list:\n\n  - \"find \\*\" — allowed \\`find . -delete\\` and \\`find . -exec rm\\`. Specific safe variants are listed instead, none of which can mutate state.\n  - \"echo \\*\" — allowed \\`echo x \u003e /etc/passwd\\`. Write redirects are now gated by checkRedirect, but plain \"echo\" is rarely needed for diagnostics, so it is dropped to stay tight by default.\n\nWrite redirects are denied unless an explicit allow rule for the synthetic \"\u003e target\" form is added (e.g. \"\u003e /tmp/\\*\").\n\n## Types\n\n```go\ntype Action string\n```\nAction represents the permission action.\n\n```go\nconst (\n\tActionAllow Action = \"allow\"\n\tActionDeny  Action = \"deny\"\n)\n```\n\n```go\ntype Checker struct {\n\t// contains filtered or unexported fields\n}\n```\nChecker checks command permissions against configured rules.\n\n```go\nfunc NewChecker(patterns map[string]string) *Checker\n```\nNewChecker creates a new permission checker from a map of patterns to actions. Rules are sorted so that the most specific rule (longest literal prefix before any '\\*') is tried first; \"\\*\" is always the fallback.\n\n```go\nfunc (c *Checker) Check(command string) error\n```\nCheck checks if a command is allowed. Returns nil if allowed, error with reason if denied.\n\n```go\nfunc (c *Checker) IsAllowed(command string) bool\n```\nIsAllowed is a convenience method that returns true if command is allowed.\n\n```go\ntype Rule struct {\n\tPattern string\n\tAction  Action\n\t// contains filtered or unexported fields\n}\n```\nRule represents a single permission rule.\n\n","path":"github.com/flashcatcloud/flashduty-runner/permission","name":"permission","synopsis":"Package permission implements glob-based command permission checking.","isRedistributable":true}
