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

Can't delete a Secret from a Vault #2374

Closed
ringods opened this issue Apr 12, 2023 · 4 comments · Fixed by #2375
Closed

Can't delete a Secret from a Vault #2374

ringods opened this issue Apr 12, 2023 · 4 comments · Fixed by #2375
Assignees
Labels
area/providers impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@ringods
Copy link
Member

ringods commented Apr 12, 2023

What happened?

When deleting a secret from a keyvault, the following error comes up:

error: keyvault.BaseClient#DeleteSecret: Failure responding to request: StatusCode=401 -- Original Error: autorest/azure: Service returned an error. Status=401 Code="Unauthorized" Message="AKV10022: Invalid audience. Expected https://vault.azure.net, found: https://management.azure.com/."

Expected Behavior

Secrets can be created and deleted with the credentials provided by the user.

Steps to reproduce

Run pulumi up with this app:

import * as azure_native from '@pulumi/azure-native';
import * as azure_native_auth from '@pulumi/azure-native/authorization';
import * as pulumi from '@pulumi/pulumi';

// Access the current configuration from Azure
const config = pulumi.output(azure_native_auth.getClientConfig());
const subscriptionId = config.subscriptionId;
const currentObjectId = config.objectId;
const tenantId = config.tenantId;

const rg = new azure_native.resources.ResourceGroup('resourceGroup', {
  location: 'westeurope',
  resourceGroupName: 'rgtest',
});

const vault = new azure_native.keyvault.Vault('vault', {
  location: rg.location,
  properties: {
    accessPolicies: [
      {
        objectId: currentObjectId,
        permissions: {
          keys: [
            'Get',
            'List',
            'Update',
            'Create',
            'Import',
            'Delete',
            'Recover',
            'Backup',
            'Restore',
            'GetRotationPolicy',
            'SetRotationPolicy',
            'Rotate',
            'Encrypt',
            'Decrypt',
            'UnwrapKey',
            'WrapKey',
            'Verify',
            'Sign',
            'Purge',
            'Release',
          ],
          secrets: [
            'get',
            'list',
            'set',
            'delete',
            'recover',
            'backup',
            'restore',
            'purge',
          ],
          certificates: [
            'get',
            'list',
            'update',
            'create',
            'import',
            'delete',
            'recover',
            'backup',
            'restore',
            'managecontacts',
            'manageissuers',
            'getissuers',
            'listissuers',
            'setissuers',
            'deleteissuers',
            'purge',
          ],
        },
        tenantId: tenantId,
      },
    ],
    enabledForDeployment: true,
    enabledForDiskEncryption: true,
    enabledForTemplateDeployment: true,
    enablePurgeProtection: true,
    enableSoftDelete: true,
    sku: {
      family: 'A',
      name: azure_native.keyvault.SkuName.Standard,
    },
    tenantId: tenantId,
  },
  resourceGroupName: rg.name,
  vaultName: 'sample-vault-27123123123',
});

const secret = new azure_native.keyvault.Secret('secret', {
  properties: {
    value: 'secret-value',
  },
  resourceGroupName: rg.name,
  secretName: 'secret-name',
  vaultName: vault.name,
});

Then run pulumi destroy. Using az login for the credentials leads to the error reported.

Output of pulumi about

CLI          
Version      3.62.0
Go Version   go1.20.2
Go Compiler  gc

Plugins
NAME          VERSION
azure-native  1.99.1
nodejs        unknown

Host     
OS       darwin
Version  13.3
Arch     arm64

This project is written in nodejs: executable='/Users/ringods/.volta/bin/node' version='v16.19.1'

Current Stack: team-ce/keyvault-delete-secret/ringo

TYPE                                  URN
pulumi:pulumi:Stack                   urn:pulumi:ringo::keyvault-delete-secret::pulumi:pulumi:Stack::keyvault-delete-secret-ringo
pulumi:providers:azure-native         urn:pulumi:ringo::keyvault-delete-secret::pulumi:providers:azure-native::default_1_99_1
azure-native:resources:ResourceGroup  urn:pulumi:ringo::keyvault-delete-secret::azure-native:resources:ResourceGroup::resourceGroup
azure-native:keyvault:Vault           urn:pulumi:ringo::keyvault-delete-secret::azure-native:keyvault:Vault::vault
azure-native:keyvault:Secret          urn:pulumi:ringo::keyvault-delete-secret::azure-native:keyvault:Secret::secret


Found no pending operations associated with team-ce/ringo

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/ringods
User           ringods
Organizations  ringods, team-ce, pulumiverse, demo

Dependencies:
NAME                  VERSION
@pulumi/azure-native  1.99.1
@pulumi/pulumi        3.62.0
@types/node           16.18.23

Additional context

Stackoverflow answer explaining more about the audience requirement on the token when working with the keyvault APIs:

https://stackoverflow.com/a/60221087

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@ringods ringods added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Apr 12, 2023
@kpitzen kpitzen added impact/usability Something that impacts users' ability to use the product easily and intuitively area/providers and removed needs-triage Needs attention from the triage team labels Apr 12, 2023
thomas11 added a commit that referenced this issue Apr 12, 2023
- Fixes #2374 
- Fix wrong error message for OIDC auth
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Apr 12, 2023
@lukehoban lukehoban added this to the 0.87 milestone Apr 17, 2023
@thecodetinker
Copy link

Hi - we've run into exactly this issue when upgrading from 1.98.1 to 1.101.0. We're using Managed Identity (ARM_USE_MSI) with the Pulumi Automation API.

Is there anything we need to do our side to support the MSAL/ADAL changes? Would using the Automation API make any difference? Is it a possible regression? Just keen to see if you have any ideas before we spend lots of time trying to figure this out. Thanks!

@thomas11
Copy link
Contributor

thomas11 commented May 3, 2023

Hi @thecodetinker, sorry to hear you're having trouble with the upgrade. Just to double-check: the exact same code and configuration worked with 1.98.1?

I just took another look at the code and couldn't see an obvious issue. It may be something particular to MSI.

@thecodetinker
Copy link

Hi, yep no other changes just updated the DLLs. MSI is great but a pain to debug unfortunately. Do you have means of testing MSI there?

@thomas11
Copy link
Contributor

thomas11 commented May 4, 2023

Unfortunately, we don't have automated MSI tests at this point because they'd need to run on Azure while our CI suite runs on GitHub.

I opened #2432 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/providers impact/usability Something that impacts users' ability to use the product easily and intuitively kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants