Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the credential validation to use azidentity #1381

Merged
merged 3 commits into from
Mar 24, 2022

Conversation

benashz
Copy link
Contributor

@benashz benashz commented Mar 24, 2022

Credential validation now relies on listing of the resource principles
to determine success. If the client credentials can successfully list
the principles once then the credentials provided from Vault are deemed
to be valid. In the case where the 401 HTTP status code is returned from
the Azure API, the validation check is terminated since this means that
the credentials were not authorized to perform any API requests.

Community Note

  • Please vote on this pull request by adding a 馃憤 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #881

Release note for CHANGELOG:


Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

Credential validation now relies on listing of the resource principles
to determine success. If the client credentials can successfully list
the principles once then the credentials provided from Vault are deemed
to be valid. In the case where the 401 HTTP status code is returned from
the Azure API, the validation check is terminated since this means that
the credentials were not authorized to perform any API requests.
if err != nil {
return fmt.Errorf("error reading from Vault: %s", err)
}
log.Printf("[DEBUG] Read %q from Vault", configPath)
log.Printf("[DEBUG] Successfully read %q from Vault", configPath)

subscriptionID := ""
Copy link
Contributor

@TechyMatt TechyMatt Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of leveraging the subscriptionId and tenantId returned from the Vault configuration, can these be optionally defined in the data source? Otherwise it'll require all Azure SPs in Vault to be granted access to a centralized Subscription that is defined in the Vault configuration, which is likely not needed by the SP that's generated for anything else. This will likely cause the provider to break for anyone with existing access defined in Vault and they'll need to update their SP definitions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, we can add that, but I think that it is out of scope for this PR. I can open another PR, but it probably won't make it into 3.4.0. Sound okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned it'll cause the provider to break for any existing vault roles that don't have access to the subscription that's defined in the Azure Secrets engine config in Vault.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR forthcoming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1384

overallSuccess = true

if pager.Err() == nil {
log.Printf("[DEBUG] Credential validation succeeded")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With num_sequential_successes being removed this will mean the moment a single Azure AD endpoint returns success then it'll assume that the credential is valid, however there can be a propogation delay between endpoints. with num_sequential_successes this allows for the provider to initiate multiple attempts to ensure credentials are replicated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I was not able to reproduce that in my testing with a 5 minute poll. I'm happy to add it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to know which endpoint we hit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe there is. Replication time seems to take longer when using an the existing SP functionality as documented here https://www.vaultproject.io/docs/secrets/azure#application-object-ids

Copy link
Contributor Author

@benashz benashz Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e71e3ef

@benashz benashz merged commit 29a312c into main Mar 24, 2022
@benashz benashz deleted the VAULT-5201/fix-d-azure-access-credentials branch March 24, 2022 20:54
@benashz benashz added this to the 3.4.0 milestone Mar 24, 2022
@robison
Copy link

robison commented Mar 25, 2022

I'm happy to raise a separate issue for this, but we ran headlong directly into the concern that @mb290 raised yesterday: #1381 (comment)

This seems to be a semi-breaking change for existing roles - could something be added to CHANGELOG.md?

@benashz
Copy link
Contributor Author

benashz commented Mar 28, 2022

This seems to be a semi-breaking change for existing roles - could something be added to CHANGELOG.md?

Hi @robison I don't believe we introduced any breaking changes with this fix. The num_sequential_successes behaviour remains the same.

Would you mind unpacking the semi-breaking change for us?

Thanks,

Ben

@robison
Copy link

robison commented Mar 29, 2022

Per @mb290's comment #1381 (comment), we had an existing Vault role that did not have access to the subscription that's defined in the Azure Secrets engine config in Vault. Thankfully ran into this in a dev environment, where the azure provider version wasn't pinned. We first pinned it back to 3.3.0, then realized that we would need to specify the subscription_id and tenant_id in 3.4.0+ - which we couldn't do until #1391 landed.

@benashz
Copy link
Contributor Author

benashz commented Mar 29, 2022

Per @mb290's comment #1381 (comment), we had an existing Vault role that did not have access to the subscription that's defined in the Azure Secrets engine config in Vault. Thankfully ran into this in a dev environment, where the azure provider version wasn't pinned. We first pinned it back to 3.3.0, then realized that we would need to specify the subscription_id and tenant_id in 3.4.0+ - which we couldn't do until #1391 landed.

Ah, I see now. Thanks for the clarification. #1391 should be going out on Thursday in a patch release 3.4.1.

@robison
Copy link

robison commented Mar 29, 2022

Excellent. Could we also get a update/note in CHANGELOG.md for v3.4.1 indicating the potential necessity of specifying subscription_id & tenant_id when using a pre-existing Vault role that doesn't have access to the subscription?

@benashz
Copy link
Contributor Author

benashz commented Mar 31, 2022

Excellent. Could we also get a update/note in CHANGELOG.md for v3.4.1 indicating the potential necessity of specifying subscription_id & tenant_id when using a pre-existing Vault role that doesn't have access to the subscription?

Updated docs in #1398

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.

vault_azure_access_credentials: num_sequential_successes does not work as expected
4 participants