-
Notifications
You must be signed in to change notification settings - Fork 29
Refactor to support separate auth for the SDK (and thus terraform) + small bugfixes #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
franklouwers
wants to merge
8
commits into
stackitcloud:main
Choose a base branch
from
franklouwers:terraform-provider-login-squashed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Refactor to support separate auth for the SDK (and thus terraform) + small bugfixes #1130
franklouwers
wants to merge
8
commits into
stackitcloud:main
from
franklouwers:terraform-provider-login-squashed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Refactor storage layer to support multiple independent storage contexts, enabling CLI and API (Terraform Provider/SDK) credentials to be stored separately. This allows users to authenticate with different accounts for CLI operations vs. SDK/Terraform usage. Key changes: - Add StorageContext enum (StorageContextCLI, StorageContextAPI) - Add *WithContext() variants for all storage functions - Support context-specific keyring service names and file paths - Maintain backward compatibility with existing storage functions - Add comprehensive tests for storage context isolation Storage locations: - CLI: stackit-cli keyring, ~/.stackit/cli-auth-storage.txt - API: stackit-cli-api keyring, ~/.stackit/cli-api-auth-storage.txt
Update authentication flows to support multiple storage contexts, enabling context-aware token management and refresh. Key changes: - Add *WithContext() variants for auth functions - Update user login flow to accept storage context parameter - Store access token expiry (JWT exp claim) instead of session expiry - Update token refresh to write tokens back to correct context - Add getAccessTokenExpiresAtUnix() to parse JWT exp claim - Update tests to use new context-aware functions This enables proper token refresh and bidirectional sync for both CLI and API authentication contexts.
Introduce 'stackit auth api' subcommand group to enable Terraform Provider and SDK to use CLI user credentials instead of requiring service accounts for local development. New commands: - stackit auth api login: Authenticate for SDK/Terraform usage - stackit auth api logout: Remove API credentials - stackit auth api get-access-token: Get valid access token (with auto-refresh) - stackit auth api status: Show API authentication status API auth uses separate storage context (StorageContextAPI) from CLI auth, allowing concurrent authentication with different accounts.
11 tasks
franklouwers
added a commit
to franklouwers/terraform-provider-stackit
that referenced
this pull request
Nov 28, 2025
This commit adds support for CLI-based authentication in the Terraform provider, enabling users to authenticate using credentials from the STACKIT CLI without managing separate service account credentials. Changes: - Add cli_auth boolean attribute to enable CLI authentication - Add cli_profile string attribute for profile selection - Implement authentication priority: explicit credentials > CLI > env vars - Integrate with SDK's WithCLIProviderAuth() configuration option The implementation follows the explicit opt-in pattern requested in RFC stackitcloud#880, requiring users to set cli_auth = true to enable the feature. Profile resolution follows the standard precedence: explicit config > STACKIT_CLI_PROFILE env var > ~/.config/stackit/cli-profile.txt > default. This change depends on SDK PR stackitcloud/stackit-sdk-go#3865 which adds the core CLI authentication functionality, and CLI PR stackitcloud/stackit-cli#1130 which implements the provider credential storage. Closes stackitcloud#719 Related to stackitcloud#880
12 tasks
franklouwers
added a commit
to franklouwers/terraform-provider-stackit
that referenced
this pull request
Nov 28, 2025
This commit adds support for CLI-based authentication in the Terraform provider, enabling users to authenticate using credentials from the STACKIT CLI without managing separate service account credentials. Changes: - Add cli_auth boolean attribute to enable CLI authentication - Add cli_profile string attribute for profile selection - Implement authentication priority: explicit credentials > CLI > env vars - Integrate with SDK's WithCLIProviderAuth() configuration option The implementation follows the explicit opt-in pattern requested in RFC stackitcloud#880, requiring users to set cli_auth = true to enable the feature. Profile resolution follows the standard precedence: explicit config > STACKIT_CLI_PROFILE env var > ~/.config/stackit/cli-profile.txt > default. This change depends on SDK PR stackitcloud/stackit-sdk-go#3865 which adds the core CLI authentication functionality, and CLI PR stackitcloud/stackit-cli#1130 which implements the provider credential storage. Closes stackitcloud#719 Related to stackitcloud#880
Replace undefined StorageContextProvider with StorageContextAPI throughout storage_test.go. Also update test expectations for keyring service names and text file names to match actual implementation (stackit-cli-api instead of stackit-cli-provider). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Update example commands to use correct path 'stackit auth api' instead of 'stackit auth provider' in login, logout, and get-access-token commands. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add nolint comments for false positive gosec warnings on auth field constants - Remove unused legacy backward compatibility constants - Remove unused createEncodedTextFile wrapper function - Add nolint comment for storagePrinter variable (used via SetStoragePrinter) - Add nolint comment for test credential false positive 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Add API Authentication for Terraform Provider Integration
This PR implements the CLI authentication feature proposed in terraform-provider-stackit#880, enabling the Terraform Provider and SDK to use CLI user credentials instead of requiring service accounts for local development. (See stackitcloud/terraform-provider-stackit#719 for the issue that triggered this as well)
Overview
Currently, the STACKIT Terraform Provider and SDK only support service account authentication (Key Flow and Token Flow), requiring users to create and manage service account credentials even for local development. This PR adds a new
stackit auth apicommand group that allows external tools to leverage the CLI's convenient OAuth2 user authentication.I also fixed a bug with token refresh expiration times.
Changes
This implementation follows the RFC's preferred approach: keychain storage with file-based fallback.
1. Storage Context System
Refactored the storage layer to support multiple independent credential contexts:
stackit auth login(existing behavior unchanged)stackit auth api login(new, isolated storage)Storage locations:
stackit-cli-api(macOS Keychain, Windows Credential Manager, Linux Secret Service)~/.stackit/cli-api-auth-storage.txt(base64-encoded)2. Token Refresh Fix
Critical improvement: Fixed token refresh mechanism to use actual JWT expiration instead of session expiration:
expclaim (typically 15min), enabling proper automatic token refreshThis fix applies to both
stackit auth loginandstackit auth api login.3. New Commands
Added
stackit auth apisubcommand group:Benefits
Usage Example
Implementation Notes
stackit auth loginbehaviorRelated
Checklist
make fmtmake generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)