auth

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

The OAuth flow, token manager, and cross-process refresh lock moved to github.com/Dynatrace/dtctl/sdk/session: every long-running consumer of the shared token store must refresh through the same locked path, so the machinery is part of the shared session layer. This file re-exports it for the root module.

What stays here is scope composition: the resource-scope tables (resource_scopes.go) that map safety levels to OAuth scopes also feed the `dtctl commands` catalog — they are CLI domain. The sdk's OAuth constructors take the composed scope list as an argument; the wrappers below keep this package's historical signatures by composing it.

Index

Constants

View Source
const (
	EnvironmentProd = session.EnvironmentProd
	EnvironmentDev  = session.EnvironmentDev
	EnvironmentHard = session.EnvironmentHard

	OAuthTokenPrefix   = session.OAuthTokenPrefix
	TokenRefreshBuffer = session.TokenRefreshBuffer

	TokenStorageKeyring = session.TokenStorageKeyring
	TokenStorageFile    = session.TokenStorageFile
)
View Source
const DashboardMigrationScope = "environment-api:dashboard-3rdgen-migration:execute"

DashboardMigrationScope lets a request convert a classic dashboard into 3rd gen dashboard content. No built-in command uses it yet; requesting it at login is what lets `exec api` reach the conversion. Every level requests it: the conversion only returns the content and saves nothing, so storing the result still takes the document write scopes.

View Source
const DocumentAdminScope = "document:documents:admin"

DocumentAdminScope lets a Document API request act as the effective owner of every document (`get documents|dashboards|notebooks --admin-access`, which sends admin-access=true). The API refuses such a request with 403 "Insufficient permissions to request admin-access" unless the token carries this scope *and* the tenant's IAM policy grants the permission of the same name — two separate gates.

It is not tied to a resource access level, because no plain document operation needs it: the flag alone does (see flagScopeRequirements in cmd/). Login requests it from readwrite-all upward. That covers the administrative levels the flag is meant for, and it is harmless for a user whose policy lacks the permission: the OAuth client is allowed to request the scope, the token merely carries it, and without the IAM permission the API still says no. readonly and readwrite-mine leave it out on purpose — acting as the owner of other people's documents is exactly what those levels exist to rule out.

Variables

View Source
var CommandScopes = map[string][]string{

	"verify analyzer": {"davis:analyzers:execute"},

	"share document":    shareScopes,
	"share dashboard":   shareScopes,
	"share notebook":    shareScopes,
	"unshare document":  unshareScopes,
	"unshare dashboard": unshareScopes,
	"unshare notebook":  unshareScopes,
}

CommandScopes are the commands whose scopes ResourceScopes cannot express, because the verb calls other endpoints than its resource's at its access level. Keys are "<verb> <resource>" with the resource's singular name; each value replaces the resource's scopes as the command's requirement. ScopesForCommand reads them in place of ResourceScopes.

View Source
var ErrNoRefreshToken = session.ErrNoRefreshToken

ErrNoRefreshToken mirrors session.ErrNoRefreshToken (same value, so errors.Is works across both names).

View Source
var ErrOAuthSessionRevoked = session.ErrOAuthSessionRevoked

ErrOAuthSessionRevoked mirrors session.ErrOAuthSessionRevoked (same value, so errors.Is works across both names).

View Source
var QueryScopes = []string{
	"storage:logs:read",
	"storage:events:read",
	"storage:metrics:read",
	"storage:spans:read",
	"storage:bizevents:read",
	"storage:entities:read",
	"storage:smartscape:read",
	"storage:system:read",
	"storage:security.events:read",
}

QueryScopes are the Grail read scopes required by DQL (`query`, `verify`, `wait`). They attach to those verbs rather than to a managed resource.

View Source
var ResourceScopes = map[string]AccessScopes{

	"workflow":           {Read: []string{"automation:workflows:read"}, Write: []string{"automation:workflows:write"}, Run: []string{"automation:workflows:run"}},
	"workflow-execution": {Read: []string{"automation:workflows:read"}},
	"wfe-task-result":    {Read: []string{"automation:workflows:read"}},

	"scheduling-rule": {Read: []string{"automation:rules:read"}, Write: []string{"automation:rules:write"}, Delete: []string{"automation:rules:write", "automation:rules:read"}},

	"document":  {Read: []string{"document:documents:read"}, Write: []string{"document:documents:write"}, Delete: []string{"document:documents:delete"}},
	"dashboard": {Read: []string{"document:documents:read"}, Write: []string{"document:documents:write"}, Delete: []string{"document:documents:delete"}},
	"notebook":  {Read: []string{"document:documents:read"}, Write: []string{"document:documents:write"}, Delete: []string{"document:documents:delete"}},
	"trash":     {Read: []string{"document:trash.documents:read"}, Write: []string{"document:trash.documents:restore"}, Delete: []string{"document:trash.documents:delete"}},

	"environment-share": {Claim: []string{"document:environment-shares:claim"}},

	"arrivals": {Read: QueryScopes},

	"bucket": {
		Read:   []string{"storage:bucket-definitions:read"},
		Write:  []string{"storage:bucket-definitions:write"},
		Delete: []string{"storage:bucket-definitions:delete", "storage:bucket-definitions:read"},
	},
	"lookup":  {Read: []string{"storage:files:read"}, Write: []string{"storage:files:write"}, Delete: []string{"storage:files:delete"}},
	"segment": {Read: []string{"storage:filter-segments:read"}, Write: []string{"storage:filter-segments:write"}, Delete: []string{"storage:filter-segments:delete"}},

	"setting":         {Read: []string{"settings:objects:read", "app-settings:objects:read"}, Write: []string{"settings:objects:write"}},
	"settings-schema": {Read: []string{"settings:schemas:read"}},

	"slo":          {Read: []string{"slo:slos:read", "slo:objective-templates:read"}, Write: []string{"slo:slos:write"}, Run: []string{"slo:slos:read"}},
	"slo-template": {Read: []string{"slo:objective-templates:read"}},

	"extension":        {Read: []string{"extensions:definitions:read"}, Write: []string{"extensions:definitions:write"}},
	"extension-config": {Read: []string{"extensions:configurations:read"}, Write: []string{"extensions:configurations:write"}},

	"app":         {Read: []string{"app-engine:apps:run"}, Write: []string{"app-engine:apps:install"}, Delete: []string{"app-engine:apps:delete"}},
	"function":    {Read: []string{"app-engine:apps:run"}, Run: []string{"app-engine:functions:run"}},
	"edgeconnect": {Read: []string{"app-engine:edge-connects:read"}, Write: []string{"app-engine:edge-connects:write"}, Delete: []string{"app-engine:edge-connects:delete"}},

	"intent": {Read: []string{"app-engine:apps:run"}},

	"action": {Read: []string{"app-engine:apps:run"}},

	"sdk-version": {Read: []string{"app-engine:apps:run"}},

	"analyzer": {Read: []string{"davis:analyzers:read"}, Run: []string{"davis:analyzers:execute"}},
	"copilot":  {Run: []string{"davis-copilot:conversations:execute"}},

	"copilot-skill": {Read: []string{"davis-copilot:conversations:execute"}},

	"notification": {Read: []string{"notification:notifications:read"}, Write: []string{"notification:notifications:write"}},

	"user":  {Read: []string{"iam:users:read"}},
	"group": {Read: []string{"iam:groups:read"}},

	"breakpoint": {Read: []string{"dev-obs:breakpoints:set"}, Write: []string{"dev-obs:breakpoints:set"}, Delete: []string{"dev-obs:breakpoints:set"}},
	"snapshot":   {Read: []string{"dev-obs:breakpoints:set"}},

	"hub-extension":         {Read: []string{"hub:catalog:read"}},
	"hub-extension-release": {Read: []string{"hub:catalog:read"}},

	"anomaly-detector": {Read: []string{"settings:objects:read"}, Write: []string{"settings:objects:write"}},

	"classic-pipelines": {Read: []string{"settings:objects:read"}},

	"lql-to-dql": {Read: []string{"openpipeline:configurations:read"}},

	"openpipeline-matcher":       {Read: []string{"openpipeline:configurations:read"}},
	"openpipeline-dql-processor": {Read: []string{"openpipeline:configurations:read"}},
	"preview-processor":          {Read: []string{"openpipeline:configurations:read"}},

	"aws":   {Read: []string{"settings:objects:read", "extensions:configurations:read"}, Write: []string{"settings:objects:write", "extensions:configurations:write"}},
	"azure": {Read: []string{"settings:objects:read", "extensions:configurations:read"}, Write: []string{"settings:objects:write", "extensions:configurations:write"}},
	"gcp":   {Read: []string{"settings:objects:read", "extensions:configurations:read"}, Write: []string{"settings:objects:write", "extensions:configurations:write"}},

	"api": {},

	"environment":      platformManagementRead,
	"license":          platformManagementRead,
	"license-settings": platformManagementRead,
}

ResourceScopes is the single source of truth for which scope each (resource, access) pair requires. Keys are the canonical *singular* resource name as it appears in the `dtctl commands` catalog (plural names resolve via ScopesForResource). GetScopesForSafetyLevel is composed from this table plus the non-resource scope groups below, so the per-command scopes and the per-safety-level OAuth union cannot diverge.

Scope strings mirror docs/TOKEN_SCOPES.md ("Quick Reference by Resource Type") and were verified against each resource's API endpoint (the path the SDK/resource handler calls); inline comments cite the endpoint where the mapping is non-obvious.

Functions

func AlternativeScopesForResource

func AlternativeScopesForResource(resource string, access Access) [][]string

AlternativeScopesForResource returns the scope sets the platform accepts in place of ScopesForResource(resource, access), or nil when that requirement has no alternative. Names resolve as in ScopesForResource.

func DecodeRefreshTokenExpiry

func DecodeRefreshTokenExpiry(refreshToken string) (time.Time, bool)

func ExtractJWTScopes

func ExtractJWTScopes(accessToken string) []string

ExtractJWTScopes returns the granted scopes decoded from a JWT access token, or nil when they cannot be determined. Used as a fallback for scope display when the scope string was dropped from compact keyring storage.

func GetScopesForSafetyLevel

func GetScopesForSafetyLevel(level config.SafetyLevel) []string

GetScopesForSafetyLevel returns the OAuth scopes required for a given safety level. The union is composed from the canonical ResourceScopes table plus the non-resource scope groups in resource_scopes.go, so the per-command scopes surfaced by `dtctl commands` cannot diverge from what login actually requests.

func HasResourceScopes

func HasResourceScopes(resource string) bool

HasResourceScopes reports whether the resource has an entry in the canonical table (regardless of whether any access level is populated).

func IsLocalResource

func IsLocalResource(name string) bool

IsLocalResource reports whether the named subcommand operates only on the local machine and needs no platform scopes.

func IsOAuthToken

func IsOAuthToken(tokenName string) bool

func IsTokenExpired

func IsTokenExpired(tokens *TokenSet) bool

func ScopesForCommand

func ScopesForCommand(verb, resource string, access Access) []string

ScopesForCommand returns the scopes verb requires on resource: its CommandScopes entry, or else ScopesForResource at access.

func ScopesForResource

func ScopesForResource(resource string, access Access) []string

ScopesForResource returns the scopes required for the given access level of a resource. The resource name may be singular or plural ("workflow" or "workflows"); aliases must be resolved by the caller. Returns nil when the resource has no scope mapping (e.g. a local-only command).

Types

type Access

type Access string

Access is the access level a command verb needs against a resource. It is derived from the verb and its safety operation (see AccessForVerb), not hand-listed per command.

const (
	AccessRead   Access = "read"
	AccessWrite  Access = "write"
	AccessDelete Access = "delete"
	AccessRun    Access = "run"
	AccessClaim  Access = "claim"
)

func AccessForVerb

func AccessForVerb(verb, safetyOp string) Access

AccessForVerb derives the access level a verb needs from its name and safety operation. exec maps to run; OperationDelete maps to delete; any other mutating operation maps to write; everything else is read. safetyOp is the MutatingVerbs value (e.g. "OperationDelete") or "" for read-only verbs.

type AccessScopes

type AccessScopes struct {
	Read   []string `json:"read,omitempty" yaml:"read,omitempty"`
	Write  []string `json:"write,omitempty" yaml:"write,omitempty"`
	Delete []string `json:"delete,omitempty" yaml:"delete,omitempty"`
	Run    []string `json:"run,omitempty" yaml:"run,omitempty"`
	Claim  []string `json:"claim,omitempty" yaml:"claim,omitempty"`
	// Alternatives maps an access level to the scope sets accepted instead of
	// its list. Any one fully granted set satisfies the level.
	Alternatives map[Access][][]string `json:"alternatives,omitempty" yaml:"alternatives,omitempty"`
}

AccessScopes lists the OAuth/IAM scopes required for each access level of a single resource type. A nil/empty list means the access level either does not apply to the resource or has no distinct scope. Delete falls back to Write when Delete is empty, matching resources that fold deletion into their write scope (e.g. workflows) rather than exposing a distinct :delete scope (e.g. documents).

The per-level lists are conjunctive: a token needs every scope in them. Alternatives covers the endpoints that document "one of the following scopes is required": each entry is another complete scope set the platform accepts in place of that level's list. The list stays the one dtctl requests at login and reports as required; an alternative only lets a scope check accept a token that holds it instead.

func (AccessScopes) AlternativesFor

func (a AccessScopes) AlternativesFor(access Access) [][]string

AlternativesFor returns the scope sets accepted in place of For(access), applying the same delete→write fallback so an alternative always refers to the list For returned.

func (AccessScopes) For

func (a AccessScopes) For(access Access) []string

For returns the scopes required for the given access level, applying the delete→write fallback for resources without a distinct delete scope.

type Environment

type Environment = session.Environment

func DetectEnvironment

func DetectEnvironment(environmentURL string) Environment

type OAuthConfig

type OAuthConfig = session.OAuthConfig

func AccountOAuthConfig

func AccountOAuthConfig(env Environment, safetyLevel config.SafetyLevel, accountUUID string) *OAuthConfig

AccountOAuthConfig returns an OAuth config for account-plane operations. The resource is set to "urn:dtaccount:{uuid}" per Dynatrace account OAuth spec.

func DefaultOAuthConfig

func DefaultOAuthConfig() *OAuthConfig

DefaultOAuthConfig returns the default OAuth configuration for production with the default safety level's scopes.

func OAuthConfigForEnvironment

func OAuthConfigForEnvironment(env Environment, safetyLevel config.SafetyLevel) *OAuthConfig

OAuthConfigForEnvironment creates an OAuth configuration for the specified environment with the scopes composed for the safety level.

func OAuthConfigFromEnvironmentURL

func OAuthConfigFromEnvironmentURL(environmentURL string) *OAuthConfig

OAuthConfigFromEnvironmentURL creates an OAuth configuration by detecting the environment from a URL, with the default safety level's scopes.

func OAuthConfigFromEnvironmentURLWithSafety

func OAuthConfigFromEnvironmentURLWithSafety(environmentURL string, safetyLevel config.SafetyLevel) *OAuthConfig

OAuthConfigFromEnvironmentURLWithSafety creates an OAuth configuration with the scopes composed for the given safety level.

type OAuthFlow

type OAuthFlow = session.OAuthFlow

func NewOAuthFlow

func NewOAuthFlow(cfg *OAuthConfig) (*OAuthFlow, error)

type StoredToken

type StoredToken = session.StoredToken

type TokenManager

type TokenManager = session.TokenManager

func NewTokenManager

func NewTokenManager(oauthConfig *OAuthConfig) (*TokenManager, error)

type TokenSet

type TokenSet = session.TokenSet

type TokenStorage

type TokenStorage = session.TokenStorage

TokenStorage names the store an OAuth token actually lives in.

type UserInfo

type UserInfo = session.OAuthUserInfo

UserInfo is the SSO userinfo response (session.OAuthUserInfo).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL