feat: add auth_mode for explicit auth configuration#3246
feat: add auth_mode for explicit auth configuration#3246laughedelic wants to merge 11 commits intointegrations:mainfrom
Conversation
|
👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with |
|
Thinking some more about the UPD: Maybe I'm just overcomplicating it. Feel free to ignore this. |
deiga
left a comment
There was a problem hiding this comment.
I think this is looking great!
I've been wanting to get to this for a while now 😬
Left a few minor comments
github/provider.go
Outdated
| var appID, appInstallationID, appPemFile string | ||
| switch authMode { | ||
| case "anonymous": | ||
| log.Printf("[INFO] Auth mode: anonymous") |
There was a problem hiding this comment.
Could you test if we can use tflog inside this func?
github/provider.go
Outdated
| case "token": | ||
| token = d.Get("token").(string) | ||
| if token == "" { | ||
| return nil, diag.FromErr(fmt.Errorf( |
There was a problem hiding this comment.
| return nil, diag.FromErr(fmt.Errorf( | |
| return nil, diag.Errorf( |
| "app_id": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| DefaultFunc: schema.EnvDefaultFunc("GITHUB_APP_ID", nil), | ||
| Description: descriptions["app_id"], | ||
| }, | ||
| "app_installation_id": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| DefaultFunc: schema.EnvDefaultFunc("GITHUB_APP_INSTALLATION_ID", nil), | ||
| Description: descriptions["app_installation_id"], | ||
| }, | ||
| "app_private_key": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| Sensitive: true, | ||
| DefaultFunc: schema.EnvDefaultFunc("GITHUB_APP_PRIVATE_KEY", nil), | ||
| Description: descriptions["app_private_key"], | ||
| }, |
There was a problem hiding this comment.
Could you add ConflictsWith fields so that it's not possible to set both App auth configs at the same time? Or does that interfere with the DefaultFunc being the same?
There was a problem hiding this comment.
I don't think it interferes with the default value, but it probably doesn't raise the conflict when everything is set through env vars. In any case, I added mutually exclusive ConflictsWith in e3264c4. And further validation is done in providerConfigure.
github/provider_test.go
Outdated
| }) | ||
| }) | ||
|
|
||
| t.Run("can be configured with top-level app fields without auth_mode", func(t *testing.T) { |
There was a problem hiding this comment.
Hmm, I would prefer if this wouldn't be possible. Can we force setting of auth_mode for top-level app fields? Or are we limited by backwards compatibility?
There was a problem hiding this comment.
This is a bit more involved than just requiring auth_mode = app if the top-lvel app fields are set. I added an extra validation in the "default" case, to make sure that if the top-level fields are set and there is no app_auth block, we get an error about setting auth_mode.
There are cases when user can set both the token and the app values, but then choose which set of credentials to use via auth_mode. Any or all of them can be set via env vars. So I think this shouldn't be too strict.
See af6fb59. I added some extra tests for the edge cases. Let me know if we're on the same page.
deiga
left a comment
There was a problem hiding this comment.
Whoo! This seems so much simpler than what I had thought it would be 😬
I hope we're not missing something
|
@stevehipwell could you give some feedback here? |
This PR
auth_mode: 'anonymous'#3117auth_modeis set explicitly)Before the change?
app_auth {}block is the only way to configure GitHub App authentication; switching between token and app auth requires modifying provider configuration codeapp_auth {}block is required due to a Terraform SDK limitation ([FEAT]: Switching Between PAT and GitHub App Authentication Without Modifying Terraform Code #1877)GITHUB_TOKENis in the environment orghCLI has a valid session, anonymous mode is impossible ([MAINT]: Rework provider auth configuration #3116)After the change?
Based on the proposal in #3116:
auth_modeargument enables explicit control over authentication:auth_mode = "anonymous"ignores any credentialsauth_mode = "token"errors if no token is provided instead of silently falling backauth_mode = "app"errors if app credentials are missing or incompleteauth_modeis not set, the existing auto-detection behavior is preserved (backward compatible)app_id,app_installation_id,app_private_keyarguments allow app auth without theapp_authblock, making it possible to switch between token and app auth purely via environment variables (addressing [FEAT]: Switching Between PAT and GitHub App Authentication Without Modifying Terraform Code #1877)app_authblock is deprecated with a mention of the new top-level argumentsgh auth tokenCLI fallback is deprecated (as proposed in [MAINT]: Rework provider auth configuration #3116)Note, I took the liberty to name the new top-level argument
app_private_keyinstead ofapp_pem_filebecause I believe it is more clear that the expected value is a private key content, not a file reference. I remember there was this old comment:Pull request checklist
Does this introduce a breaking change?
I didn't implement
environment_variable_prefixandauth_typefrom the #3116's proposal to keep this focused, and implementing those seemed like touching many more places. But I can add those separately.