Repository navigation
DEV-3258: OIDC Token Exchange - #1278
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1278 +/- ##
==========================================
+ Coverage 49.88% 50.27% +0.39%
==========================================
Files 236 236
Lines 25621 25694 +73
==========================================
+ Hits 12780 12917 +137
+ Misses 11222 11127 -95
- Partials 1619 1650 +31
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughThe changes introduce support for exchanging a GitHub Actions OIDC token for an Atmos Pro API token during authentication, falling back to the existing API token method if OIDC is unavailable. This includes new error handling, helper functions, configuration constants, request/response structs, and comprehensive tests for the new authentication flow. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant APIClient
participant GitHubOIDC
participant AtmosProAPI
User->>APIClient: NewAtmosProAPIClientFromEnv()
APIClient->>APIClient: Check for API token in env
alt API token not found
APIClient->>APIClient: Check for GitHub OIDC env vars
APIClient->>GitHubOIDC: GET OIDC token (with audience)
GitHubOIDC-->>APIClient: OIDC token (.value)
APIClient->>APIClient: Get workspace ID from env
APIClient->>AtmosProAPI: POST /auth/github-oidc (token, workspaceId)
AtmosProAPI-->>APIClient: Atmos API token
else API token found
APIClient->>APIClient: Use API token
end
APIClient-->>User: Initialized client or error
Assessment against linked issues
Suggested reviewers
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (5)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/pro/api_client.go (2)
257-257: Use HTTP client with timeout.Consider using an HTTP client with a timeout instead of
http.DefaultClientto prevent hanging requests.- resp, err := http.DefaultClient.Do(req) + client := &http.Client{Timeout: 10 * time.Second} + resp, err := client.Do(req)
296-296: Use HTTP client with timeout.For consistency and to prevent hanging requests, use an HTTP client with a timeout.
- resp, err := http.DefaultClient.Do(req) + client := &http.Client{Timeout: 10 * time.Second} + resp, err := client.Do(req)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
pkg/config/const.go(1 hunks)pkg/pro/api_client.go(10 hunks)pkg/pro/api_client_test.go(2 hunks)pkg/pro/requests.go(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
pkg/pro/api_client.go (1)
Learnt from: osterman
PR: cloudposse/atmos#1202
File: pkg/utils/yaml_func_exec.go:104-104
Timestamp: 2025-04-23T15:02:50.246Z
Learning: In the Atmos codebase, direct calls to `os.Getenv` should be avoided. Instead, use `viper.BindEnv` for environment variable access. This provides a consistent approach to configuration management across the codebase.
🪛 GitHub Check: codecov/patch
pkg/pro/api_client.go
[warning] 90-91: pkg/pro/api_client.go#L90-L91
Added lines #L90 - L91 were not covered by tests
[warning] 96-96: pkg/pro/api_client.go#L96
Added line #L96 was not covered by tests
[warning] 105-105: pkg/pro/api_client.go#L105
Added line #L105 was not covered by tests
[warning] 120-120: pkg/pro/api_client.go#L120
Added line #L120 was not covered by tests
[warning] 125-125: pkg/pro/api_client.go#L125
Added line #L125 was not covered by tests
[warning] 132-132: pkg/pro/api_client.go#L132
Added line #L132 was not covered by tests
[warning] 137-137: pkg/pro/api_client.go#L137
Added line #L137 was not covered by tests
[warning] 151-151: pkg/pro/api_client.go#L151
Added line #L151 was not covered by tests
[warning] 156-156: pkg/pro/api_client.go#L156
Added line #L156 was not covered by tests
[warning] 161-161: pkg/pro/api_client.go#L161
Added line #L161 was not covered by tests
[warning] 167-167: pkg/pro/api_client.go#L167
Added line #L167 was not covered by tests
[warning] 176-176: pkg/pro/api_client.go#L176
Added line #L176 was not covered by tests
[warning] 198-198: pkg/pro/api_client.go#L198
Added line #L198 was not covered by tests
[warning] 203-203: pkg/pro/api_client.go#L203
Added line #L203 was not covered by tests
[warning] 208-208: pkg/pro/api_client.go#L208
Added line #L208 was not covered by tests
[warning] 214-214: pkg/pro/api_client.go#L214
Added line #L214 was not covered by tests
[warning] 223-223: pkg/pro/api_client.go#L223
Added line #L223 was not covered by tests
[warning] 244-245: pkg/pro/api_client.go#L244-L245
Added lines #L244 - L245 were not covered by tests
[warning] 252-253: pkg/pro/api_client.go#L252-L253
Added lines #L252 - L253 were not covered by tests
[warning] 259-260: pkg/pro/api_client.go#L259-L260
Added lines #L259 - L260 were not covered by tests
[warning] 269-270: pkg/pro/api_client.go#L269-L270
Added lines #L269 - L270 were not covered by tests
[warning] 286-287: pkg/pro/api_client.go#L286-L287
Added lines #L286 - L287 were not covered by tests
[warning] 291-292: pkg/pro/api_client.go#L291-L292
Added lines #L291 - L292 were not covered by tests
[warning] 298-299: pkg/pro/api_client.go#L298-L299
Added lines #L298 - L299 were not covered by tests
[warning] 303-304: pkg/pro/api_client.go#L303-L304
Added lines #L303 - L304 were not covered by tests
[warning] 308-309: pkg/pro/api_client.go#L308-L309
Added lines #L308 - L309 were not covered by tests
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Summary
🔇 Additional comments (6)
pkg/config/const.go (1)
92-92: LGTM!The new constant follows the established naming pattern and integrates well with the existing Atmos Pro configuration constants.
pkg/pro/requests.go (1)
9-23: Well-structured OIDC data types.The new structs are properly defined with clear JSON tags and descriptive comments. They provide a clean interface for the OIDC token exchange flow.
pkg/pro/api_client_test.go (1)
150-266: Excellent test coverage for OIDC authentication.The test comprehensively covers all authentication scenarios with proper environment variable management and viper configuration reset between test cases. Good use of httptest servers for mocking external dependencies.
pkg/pro/api_client.go (3)
18-42: Good error handling standardization.The predefined error variables and format string constant improve error consistency across the package. This makes error handling more maintainable and debugging easier.
64-100: Good implementation of OIDC authentication with proper fallback.The authentication flow correctly prioritizes API token and falls back to OIDC when needed. Excellent use of viper for environment variable access, which addresses the previous review feedback about avoiding direct
os.Getenvcalls.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 90-91: pkg/pro/api_client.go#L90-L91
Added lines #L90 - L91 were not covered by tests
[warning] 96-96: pkg/pro/api_client.go#L96
Added line #L96 was not covered by tests
105-105: Consistent error handling improvements.The migration to predefined error variables and consistent error formatting enhances maintainability and debugging capabilities across all API client methods.
Also applies to: 120-121, 125-126, 132-133, 137-138, 151-152, 156-157, 161-162, 167-168, 176-177, 185-186, 198-199, 203-204, 208-209, 214-215, 223-224, 232-233
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 105-105: pkg/pro/api_client.go#L105
Added line #L105 was not covered by tests
what
This pull request introduces significant enhancements to the
AtmosProAPIClientto support GitHub OIDC token-based authentication, improve error handling, and add corresponding unit tests. The changes include the addition of new constants, error definitions, helper functions for OIDC token management, and updates to existing methods to handle the new authentication flow.Authentication Enhancements:
pkg/pro/api_client.go,pkg/pro/requests.go) [1] [2] [3]getGitHubOIDCTokenandexchangeOIDCTokenForAtmosTokento retrieve and exchange OIDC tokens for Atmos Pro tokens. (pkg/pro/api_client.go)Error Handling Improvements:
pkg/pro/api_client.go)pkg/pro/api_client.go) [1] [2] [3] [4] [5] [6] [7]Configuration Updates:
os.Getenvwithviper.GetStringfor environment variable management, enabling better configuration handling. (pkg/pro/api_client.go)ATMOS_PRO_WORKSPACE_IDfor OIDC authentication. (pkg/config/const.go)Unit Tests:
pkg/pro/api_client_test.go)Struct Additions:
GitHubOIDCAuthRequest,GitHubOIDCAuthResponse,GitHubOIDCResponse). (pkg/pro/requests.go)why
Currently all the Atmos Pro functionality reads the API token out of the environment. We should leave that in place, but should use that token second only if we can't exchange an OIDC token for an Atmos token.
references
Summary by CodeRabbit
New Features
Bug Fixes
Tests