Skip to content

feat(credentials): add the core/credentials package and config.WithTokenProvider - #12949

Open
JorTurFer wants to merge 1 commit into
stackitcloud:mainfrom
JorTurFer:feat/identity-pkg
Open

JorTurFer wants to merge 1 commit into
stackitcloud:mainfrom
JorTurFer:feat/identity-pkg

Conversation

@JorTurFer

@JorTurFer JorTurFer commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds core/credentials, a package of modular token providers, and config.WithTokenProvider to use one of them with any service client. The existing authentication flows are not modified: this is an additive, opt-in way to authenticate.

Status: draft. The public SDK is a contract, so this is not to be merged until the integration of the package with the control plane SDK has been validated.

What is added

  • One contract. TokenProvider returns an access token and nothing else. Each authentication flow is a provider:
    WorkloadIdentityFederationProvider, ServiceAccountKeyProvider, StaticTokenProvider, InstanceMetadataProvider and CLIProvider.
  • Composition. ChainedProvider tries providers in order, and NewDefaultProvider builds the default chain: workload identity federation, service account key, static token, instance metadata and, only if enabled (EnableCLI or STACKIT_USE_CLI=true), the STACKIT CLI session. The CLI is opt-in because it authenticates as the person logged in, not as the application.
  • Caching. A provider keeps one token per combination of scopes and resources, refreshes it shortly before it expires, and makes a single request when several goroutines ask at once. Resources become the aud of the token (RFC 8707).
  • Configuration. Values are resolved from the config first, then from the environment, then (for some) from the credentials file, so anything explicit in code wins. The service account key and the private key can be given as content or as a path.
  • config.WithTokenProvider. Makes auth.DefaultAuth authenticate through the provider. Options that explicitly choose how to authenticate (WithToken, WithServiceAccountKey, WithCustomAuth, ...) still take precedence over it.
  • Docs. README for the package, a section in the main README, the authentication example and the changelogs.

Design notes

  • Package name. credentials rather than identity, so it does not clash with the upcoming services/identity, and to follow the naming of other SDKs.
  • Public surface. Only the contract, the providers with their configs and constructors, the chains and SetLogger are exported. Constants, file formats and helpers are private.
  • Singleflight. The token cache has its own small singleflight instead of golang.org/x/sync/singleflight, to keep the dependencies of core to a minimum, since every service module inherits them. Using x/sync would replace it with a Group.DoChan call whose fetch runs on context.WithoutCancel.
  • Versioning. The package lives in the core module and is versioned with it (core/VERSION is bumped to v0.27.0).

Out of scope

  • The legacy authentication is neither modified nor deprecated; there is no replacement constructor yet to point to.
  • STACKIT_TOKEN_BASEURL is not supported by the new package.
  • A second builder in the generator and an end-to-end authentication test are tracked separately.

Checklist

  • [x] Issue was linked above -> Internal dicussion
  • No generated code was adjusted manually
  • Changelogs
    • Changelog in the root directory was adjusted
    • Changelog of core was adjusted
  • VERSION file of core was adjusted
  • Code format was applied
  • Examples were added / adjusted (see examples/ directory)
  • Unit tests got implemented or updated
  • Unit tests are passing: go test ./... in core
  • No linter issues: golangci-lint run --config golang-ci.yaml ./... in core

🤖 Generated with Claude Code

@JorTurFer JorTurFer changed the title feat(identity): add experimental core/identity package and config.WithTokenProvider feat(credentials): add experimental core/credentials package and config.WithTokenProvider Oct 17, 2026
@JorTurFer JorTurFer changed the title feat(credentials): add experimental core/credentials package and config.WithTokenProvider feat(credentials): add core/credentials package and config.WithTokenProvider Oct 17, 2026
@JorTurFer JorTurFer changed the title feat(credentials): add core/credentials package and config.WithTokenProvider feat(credentials): add core/credentials package Oct 17, 2026
@JorTurFer
JorTurFer force-pushed the feat/identity-pkg branch 4 times, most recently from 4c42964 to 5ecee02 Compare October 18, 2026 15:33
@JorTurFer JorTurFer changed the title feat(credentials): add core/credentials package feat(credentials): add the core/credentials package and config.WithTokenProvider Oct 18, 2026
@JorTurFer
JorTurFer marked this pull request as ready for review October 18, 2026 15:37
@JorTurFer
JorTurFer requested a review from a team as a code owner October 18, 2026 15:37
@JorTurFer JorTurFer mentioned this pull request Oct 18, 2026
2 of 11 tasks
@JorTurFer
JorTurFer force-pushed the feat/identity-pkg branch 2 times, most recently from f0cd9ac to f0f41ea Compare October 18, 2026 15:43
…kenProvider

Add core/credentials, a package of modular token providers built on one contract,
TokenProvider, which returns an access token and nothing else:

- WorkloadIdentityFederationProvider, ServiceAccountKeyProvider, StaticTokenProvider,
  InstanceMetadataProvider and CLIProvider, one per authentication flow.
- ChainedProvider, to try providers in order, and NewDefaultProvider, the default
  chain: workload identity federation, service account key, static token, instance
  metadata and, only if enabled, the STACKIT CLI session.
- Each provider caches one token per combination of scopes and resources and shares a
  single refresh between concurrent callers.
- The service account key and the private key can be given as content or as a path,
  in the config or in the environment, and the config wins over the environment.

Add config.WithTokenProvider, which makes auth.DefaultAuth authenticate through the
given provider. The existing authentication flows are not modified, and options that
explicitly choose how to authenticate still take precedence over it.

Update the authentication example and the documentation, including a README for the
package.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants