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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure cli: verifying we're authenticated as a User #27

Merged
merged 3 commits into from
Jul 15, 2019

Conversation

tombuildsstuff
Copy link
Contributor

Unfortunately when authenticating as a Service Principal not all required information is available
As such instead we support authenticating as a Service Principal using the separate auth methods
for Client Certificate/Secret authentication.

The intention of this is to give more a more helpful error when you're authenticated as a Service Principal using the Azure CLI

$ go test -v ./authentication/
=== RUN   TestAzureCLITokenAuth_isApplicable
--- PASS: TestAzureCLITokenAuth_isApplicable (0.00s)
=== RUN   TestAzureCLITokenAuth_populateConfig
--- PASS: TestAzureCLITokenAuth_populateConfig (0.00s)
=== RUN   TestAzureCLITokenAuth_validate
--- PASS: TestAzureCLITokenAuth_validate (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_builder
--- PASS: TestServicePrincipalClientCertAuth_builder (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_isApplicable
--- PASS: TestServicePrincipalClientCertAuth_isApplicable (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_populateConfig
--- PASS: TestServicePrincipalClientCertAuth_populateConfig (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_validate
--- PASS: TestServicePrincipalClientCertAuth_validate (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_builder
--- PASS: TestServicePrincipalClientSecretAuth_builder (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_isApplicable
--- PASS: TestServicePrincipalClientSecretAuth_isApplicable (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_populateConfig
--- PASS: TestServicePrincipalClientSecretAuth_populateConfig (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_validate
--- PASS: TestServicePrincipalClientSecretAuth_validate (0.00s)
=== RUN   TestManagedServiceIdentity_builder
2019/05/23 12:49:55 [DEBUG] Using MSI endpoint "https://hello-world"
--- PASS: TestManagedServiceIdentity_builder (0.00s)
=== RUN   TestManagedServiceIdentity_isApplicable
--- PASS: TestManagedServiceIdentity_isApplicable (0.00s)
=== RUN   TestManagedServiceIdentity_populateConfig
--- PASS: TestManagedServiceIdentity_populateConfig (0.00s)
=== RUN   TestManagedServiceIdentity_validate
--- PASS: TestManagedServiceIdentity_validate (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_Expired
--- PASS: TestAzureFindValidAccessTokenForTenant_Expired (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_ExpiringIn
--- PASS: TestAzureFindValidAccessTokenForTenant_ExpiringIn (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_InvalidManagementDomain
2019/05/23 12:49:55 [DEBUG] Resource "https://portal.azure.com/" isn't a management domain
--- PASS: TestAzureFindValidAccessTokenForTenant_InvalidManagementDomain (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_DifferentTenant
2019/05/23 12:49:55 [DEBUG] Resource "https://management.core.windows.net/" isn't for the correct Tenant
--- PASS: TestAzureFindValidAccessTokenForTenant_DifferentTenant (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_Valid
--- PASS: TestAzureFindValidAccessTokenForTenant_Valid (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_NoTokens
--- PASS: TestAzureFindValidAccessTokenForTenant_NoTokens (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdMissing
--- PASS: TestAzureCliProfile_populateSubscriptionIdMissing (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdNoDefault
--- PASS: TestAzureCliProfile_populateSubscriptionIdNoDefault (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdValid
--- PASS: TestAzureCliProfile_populateSubscriptionIdValid (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdEmpty
--- PASS: TestAzureCliProfile_populateTenantIdEmpty (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdMissingSubscription
--- PASS: TestAzureCliProfile_populateTenantIdMissingSubscription (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdValid
--- PASS: TestAzureCliProfile_populateTenantIdValid (0.00s)
=== RUN   TestAzureCLIProfileFindDefaultSubscription
--- PASS: TestAzureCLIProfileFindDefaultSubscription (0.00s)
=== RUN   TestAzureCLIProfileFindSubscription
--- PASS: TestAzureCLIProfileFindSubscription (0.00s)
=== RUN   TestAzureEnvironmentNames
--- PASS: TestAzureEnvironmentNames (0.00s)
PASS
ok  	github.com/hashicorp/go-azure-helpers/authentication	1.319s

Unfortunately when authenticating as a Service Principal not all required information is available
As such instead we support authenticating as a Service Principal using the separate auth methods
for Client Certificate/Secret authentication.

```
$ go test -v ./authentication/
=== RUN   TestAzureCLITokenAuth_isApplicable
--- PASS: TestAzureCLITokenAuth_isApplicable (0.00s)
=== RUN   TestAzureCLITokenAuth_populateConfig
--- PASS: TestAzureCLITokenAuth_populateConfig (0.00s)
=== RUN   TestAzureCLITokenAuth_validate
--- PASS: TestAzureCLITokenAuth_validate (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_builder
--- PASS: TestServicePrincipalClientCertAuth_builder (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_isApplicable
--- PASS: TestServicePrincipalClientCertAuth_isApplicable (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_populateConfig
--- PASS: TestServicePrincipalClientCertAuth_populateConfig (0.00s)
=== RUN   TestServicePrincipalClientCertAuth_validate
--- PASS: TestServicePrincipalClientCertAuth_validate (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_builder
--- PASS: TestServicePrincipalClientSecretAuth_builder (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_isApplicable
--- PASS: TestServicePrincipalClientSecretAuth_isApplicable (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_populateConfig
--- PASS: TestServicePrincipalClientSecretAuth_populateConfig (0.00s)
=== RUN   TestServicePrincipalClientSecretAuth_validate
--- PASS: TestServicePrincipalClientSecretAuth_validate (0.00s)
=== RUN   TestManagedServiceIdentity_builder
2019/05/23 12:49:55 [DEBUG] Using MSI endpoint "https://hello-world"
--- PASS: TestManagedServiceIdentity_builder (0.00s)
=== RUN   TestManagedServiceIdentity_isApplicable
--- PASS: TestManagedServiceIdentity_isApplicable (0.00s)
=== RUN   TestManagedServiceIdentity_populateConfig
--- PASS: TestManagedServiceIdentity_populateConfig (0.00s)
=== RUN   TestManagedServiceIdentity_validate
--- PASS: TestManagedServiceIdentity_validate (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_Expired
--- PASS: TestAzureFindValidAccessTokenForTenant_Expired (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_ExpiringIn
--- PASS: TestAzureFindValidAccessTokenForTenant_ExpiringIn (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_InvalidManagementDomain
2019/05/23 12:49:55 [DEBUG] Resource "https://portal.azure.com/" isn't a management domain
--- PASS: TestAzureFindValidAccessTokenForTenant_InvalidManagementDomain (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_DifferentTenant
2019/05/23 12:49:55 [DEBUG] Resource "https://management.core.windows.net/" isn't for the correct Tenant
--- PASS: TestAzureFindValidAccessTokenForTenant_DifferentTenant (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_Valid
--- PASS: TestAzureFindValidAccessTokenForTenant_Valid (0.00s)
=== RUN   TestAzureFindValidAccessTokenForTenant_NoTokens
--- PASS: TestAzureFindValidAccessTokenForTenant_NoTokens (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdMissing
--- PASS: TestAzureCliProfile_populateSubscriptionIdMissing (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdNoDefault
--- PASS: TestAzureCliProfile_populateSubscriptionIdNoDefault (0.00s)
=== RUN   TestAzureCliProfile_populateSubscriptionIdValid
--- PASS: TestAzureCliProfile_populateSubscriptionIdValid (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdEmpty
--- PASS: TestAzureCliProfile_populateTenantIdEmpty (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdMissingSubscription
--- PASS: TestAzureCliProfile_populateTenantIdMissingSubscription (0.00s)
=== RUN   TestAzureCliProfile_populateTenantIdValid
--- PASS: TestAzureCliProfile_populateTenantIdValid (0.00s)
=== RUN   TestAzureCLIProfileFindDefaultSubscription
--- PASS: TestAzureCLIProfileFindDefaultSubscription (0.00s)
=== RUN   TestAzureCLIProfileFindSubscription
--- PASS: TestAzureCLIProfileFindSubscription (0.00s)
=== RUN   TestAzureEnvironmentNames
--- PASS: TestAzureEnvironmentNames (0.00s)
PASS
ok  	github.com/hashicorp/go-azure-helpers/authentication	1.319s
```
@tombuildsstuff tombuildsstuff requested a review from a team May 23, 2019 10:54
@tombuildsstuff tombuildsstuff added bug Something isn't working enhancement New feature or request labels May 23, 2019
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@katbyte katbyte added this to the v0.5.0 milestone Jul 9, 2019
@tombuildsstuff tombuildsstuff changed the title [WIP] azure cli: verifying we're authenticated as a User azure cli: verifying we're authenticated as a User Jul 15, 2019
@tombuildsstuff tombuildsstuff merged commit c10ac5b into master Jul 15, 2019
@tombuildsstuff tombuildsstuff deleted the f/azure-cli-sp-auth branch July 15, 2019 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants