{"modulePath":"github.com/hashicorp/tfctl-cli","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package execsession\n\nPackage execsession manages short-lived, process-scoped permission grants that allow nested tfctl invocations to perform noninteractive deletes.\n\nThis is a safety rail, not a security boundary: the granting process and any nested tfctl run as the same OS user, so the value provided is a deliberate human opt-in that auto-reverts when the session ends. A hard guarantee that an agent cannot delete must come from the API token scope server-side.\n\n## Constants\n\n```go\nconst (\n\t// ReasonNoSession indicates no session env var was set.\n\tReasonNoSession = \"no-session\"\n\t// ReasonStale indicates the env var was set but the session file is gone.\n\tReasonStale = \"stale\"\n\t// ReasonNotLive indicates the granting process is no longer alive.\n\tReasonNotLive = \"not-live\"\n\t// ReasonClassNotGranted indicates the resource class was not permitted.\n\tReasonClassNotGranted = \"class-not-granted\"\n\t// ReasonGranted indicates the delete is authorized.\n\tReasonGranted = \"granted\"\n)\n```\nDecision reason codes returned by Authorizer implementations.\n\n```go\nconst EnvVar = \"TFCTL_EXEC_SESSION\"\n```\nEnvVar is the environment variable a wrapper sets so nested tfctl invocations can discover the active exec session token.\n\n## Functions\n\n```go\nfunc AllowsDelete(granted []string, class string) bool\n```\nAllowsDelete reports whether class is permitted by the granted set. Explicit class names always match. An empty/unknown class is always denied.\n\n```go\nfunc ClassFromPath(p string) string\n```\nClassFromPath derives the resource class being deleted from a resolved API path. The heuristic returns the collection segment immediately preceding the final id segment. It returns \"\" when it cannot be determined (fewer than two meaningful segments), which callers treat as deny-by-default.\n\n\t/organizations/tfc-demo-au       -\u003e \"organizations\"\n\t/workspaces/ws-abc               -\u003e \"workspaces\"\n\t/workspaces/ws-abc/vars/var-xyz  -\u003e \"vars\"\n\t/workspaces/ws/relationships/x   -\u003e \"x\"   (link removal; reversible)\n\t/workspaces                      -\u003e \"\"    (collection only)\n\n```go\nfunc DestroyableResourceTypes() []string\n```\nDestroyableResourceTypes returns the suggested values for --allow-delete: every known destroyable resource class.\n\n```go\nfunc NormalizeAllowDelete(in []string) (out []string, warnings []string)\n```\nNormalizeAllowDelete lowercases, trims, and CSV-splits the raw --allow-delete values into a normalized, deduplicated list of types. Unknown types (not are returned as warnings but are still kept in the output, since the API surface is large.\n\n## Types\n\n```go\ntype Authorizer interface {\n\tAuthorizeDelete(class string) (Decision, error)\n}\n```\nAuthorizer reports whether a noninteractive DELETE of a resource class is permitted by an active, live session. It is the seam the api command depends on so its behavior is testable.\n\n```go\ntype Decision struct {\n\t// Allowed reports whether the delete may proceed without a prompt.\n\tAllowed bool\n\t// Token is the session token, surfaced for audit logging (empty if none).\n\tToken string\n\t// Reason is a machine-ish explanation; see the Reason* constants.\n\tReason string\n}\n```\nDecision is the outcome of an authorization check.\n\n```go\ntype EnvAuthorizer struct {\n\tStore    *Store\n\tGetenv   func(string) string // default os.Getenv\n\tLiveness LivenessFn          // default probeLiveness\n}\n```\nEnvAuthorizer is the runtime Authorizer. It reads the session token from the environment, loads the session, and verifies the granting process is still alive before checking the granted types.\n\n```go\nfunc (a *EnvAuthorizer) AuthorizeDelete(class string) (Decision, error)\n```\nAuthorizeDelete implements Authorizer.\n\n```go\ntype Handle struct {\n\t// contains filtered or unexported fields\n}\n```\nHandle is a live grant held by the wrapper process. Close releases the lock and removes the file.\n\n```go\nfunc (h *Handle) Close() error\n```\nClose releases the advisory lock and removes the session file. It is safe to call once; subsequent calls are no-ops.\n\n```go\nfunc (h *Handle) Token() string\n```\nToken returns the session token to expose to descendant processes.\n\n```go\ntype LivenessFn func(path string) (alive bool, err error)\n```\nLivenessFn reports whether the process that granted the session file at path is still alive. It is the seam that lets authorization be tested without real processes. It reports alive=true when the granting process still holds its shared lock on the file, and alive=false once that lock has been released (the process exited or was killed).\n\n```go\ntype Permissions struct {\n\t// AllowDelete holds normalized resource types.\n\tAllowDelete []string\n}\n```\nPermissions is the set of capabilities granted to a session.\n\n```go\ntype Session struct {\n\tVersion     int      `hcl:\"version\"`\n\tToken       string   `hcl:\"token\"`\n\tPID         int      `hcl:\"pid\"`\n\tCreatedAt   string   `hcl:\"created_at\"`\n\tAllowDelete []string `hcl:\"allow_delete\"`\n}\n```\nSession is the on-disk record for an active grant.\n\n```go\ntype Store struct {\n\t// Dir is the directory session files live in. The default is the\n\t// \u003cconfig-dir\u003e/exec subdirectory resolved by profile.ConfigDir.\n\tDir string\n}\n```\nStore abstracts the directory holding session files so tests can use a temp dir.\n\n```go\nfunc DefaultStore() (*Store, error)\n```\nDefaultStore returns a Store rooted at \\\u003cconfig-dir\u003e/exec, creating the directory with 0700 permissions if needed. The config dir is resolved by profile.ConfigDir, so it honors TFCTL\\_CONFIG\\_DIR and stays consistent with where the rest of tfctl reads its configuration.\n\n```go\nfunc (s *Store) Create(perms Permissions, pid int) (*Handle, error)\n```\nCreate issues a new token, writes the session file with 0600 permissions, and acquires a shared advisory lock held open in the returned Handle. The lock is held for the process lifetime so authorizers can detect liveness.\n\n```go\nfunc (s *Store) Load(token string) (*Session, error)\n```\nLoad reads and decodes the session for token. A missing or malformed token returns an error satisfying os.IsNotExist.\n\n","path":"github.com/hashicorp/tfctl-cli/internal/pkg/execsession","name":"execsession","synopsis":"Package execsession manages short-lived, process-scoped permission grants that allow nested tfctl invocations to perform noninteractive deletes.","isRedistributable":true}
