-
Notifications
You must be signed in to change notification settings - Fork 30
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
base: main
Are you sure you want to change the base?
Refactor to support separate auth for the SDK (and thus terraform) + small bugfixes #1130
Conversation
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
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
|
Hello |
|
@JorTurFer it's not a naive question at all, and I wondered the same thing when implementing this. The RFC preferred to have a different set of keys for cli vs api use, hence the second command. |
|
@JorTurFer The intention to separate it was, that users have explicit opt-in to the CLI Auth via the CLI itself. So just because there is already an active session in the CLI from |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
Keep |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
keep |
cgoetz-inovex
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution.
Also tested the changes locally.
From my comments I'd like the docs to mention the two different contexts and to enable outputformat: YAML in get-access-token and status.
Also wishing you nice holidays!
Cheers, Carlo
|
another note: when updating the branch you will probably get some compile errors. Package |
696ce71 to
d462b08
Compare
Add new `stackit auth api` commands that provide separate credential storage for the STACKIT Terraform Provider and SDK. This allows using different accounts for CLI usage vs SDK/Provider usage. New commands: - stackit auth api login - stackit auth api logout - stackit auth api get-access-token - stackit auth api status The implementation adds a storage context system to isolate credentials between CLI and API contexts, with tokens stored in the OS keychain (with fallback to local storage).
d462b08 to
73de092
Compare
|
Thanks @cgoetz-inovex for the review. Branch updated (force-pushed, sorry about that, my local fork was a bit of a mess from previous attempts and me forgetting to clean up at the right time) |
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)