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

Refactor Provider Credentials #2195

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

Refactor Provider Credentials #2195

wants to merge 18 commits into from

Conversation

grolu
Copy link
Contributor

@grolu grolu commented Nov 21, 2024

This PR refactors the backend /cloudprovidersecrets API

  • Removed old endpoint that returned custom dashboard secret resource
  • Added new /cloudprovidercredentials endpoint that returns list of credentials (sets) that contain related SecretBinding, Secret (if own) and resolved Quota resources
  • Renamed secret store to credential store

This PR is also a preparation to support new CredentialsBinding resource

  • Started renaming secret to credential (store)
  • Work with SecretBinding as the leading resource, access referenced secret only when we need to access the actual secret data
  • In a follow-up PR we can then also read CredentialsBindings in the backend and return with the list. The dashboard can then work with CredentialsBindings and SecretBindings in the frontend as they are more or less interchangeable. Only the reference to the Secret / WorkloadIdentity data is different so we need to add some kind of abstraction / transformation there.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
Tests need to be adapted

Release note:


@gardener-robot gardener-robot added needs/review Needs review size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py) needs/second-opinion Needs second review by someone else labels Nov 21, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 21, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 21, 2024
Highlight secret row instead of open secret dialog
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 21, 2024
show secret data in edit mode
@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 22, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 22, 2024
backend/lib/services/cloudProviderCredentials.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/utils/index.js Outdated Show resolved Hide resolved
backend/lib/services/cloudProviderCredentials.js Outdated Show resolved Hide resolved
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 26, 2024
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 26, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 27, 2024
@grolu grolu force-pushed the enh/refactor-secrets branch from dbef902 to 5b82bcd Compare November 27, 2024 11:24
@gardener-robot-ci-3 gardener-robot-ci-3 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 27, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 27, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 29, 2024
@grolu grolu marked this pull request as ready for review December 2, 2024 10:22
@grolu grolu requested a review from petersutter as a code owner December 2, 2024 10:22
@grolu grolu changed the title [WIP] Refactor Provider Credentials Refactor Provider Credentials Dec 2, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Dec 2, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 2, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 2, 2024
@grolu grolu force-pushed the enh/refactor-secrets branch from d861174 to 2e1afb0 Compare December 2, 2024 12:42
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 2, 2024
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 2, 2024
@grolu grolu force-pushed the enh/refactor-secrets branch from 2e1afb0 to cee31b0 Compare December 2, 2024 16:43
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Dec 2, 2024
frontend/src/components/GShootListRow.vue Outdated Show resolved Hide resolved
import set from 'lodash/set'
import mapKeys from 'lodash/mapKeys'

export function createSecretDialogDataComposable (options) {
Copy link
Member

Choose a reason for hiding this comment

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

data is not optional

}
}

export function useSecretDialogData () {
Copy link
Member

Choose a reason for hiding this comment

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

I do not see anything that is dialog related. The api of this composable is very strange. LEt's talk about it.

frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
frontend/src/store/credential.js Outdated Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0
//

import {
Copy link
Member

@holgerkoser holgerkoser Dec 3, 2024

Choose a reason for hiding this comment

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

Add a test for this store. As template for the tests you can use:

//
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
//

import {
  setActivePinia,
  createPinia,
} from 'pinia'

import { useAppStore } from '@/store/app'
import { useAuthzStore } from '@/store/authz'
import { useCloudProfileStore } from '@/store/cloudProfile'
import { useCredentialStore } from '@/store/credential'
import { useGardenerExtensionStore } from '@/store/gardenerExtension'

import { useApi } from '@/composables/useApi'

const quotas = [{
  metadata: {
    name: 'project-quota',
    namespace: 'garden-trial',
  },
  spec: {
    scope: {
      kind: 'Project',
      apiVersion: 'core.gardener.cloud/v1beta1',
    },
    clusterLifetimeDays: 7,
  },
}]

const secretBindings = [{
  metadata: {
    name: 'aws-trial-secretbinding',
    namespace: 'garden-test',
  },
  provider: {
    type: 'aws',
  },
  quotas: [{
    name: 'project-quota',
    namespace: 'garden-trial',
  }],
  secretRef: {
    name: 'aws-secret',
    namespace: 'garden-trial',
  },
}]

const secrets = [{
  metadata: {
    name: 'aws-secret',
    namespace: 'garden-trial',
  },
  data: {
    accessKeyID: 'id',
    secretAccessKey: 'supersecret',
  },
}]

describe('stores', () => {
  describe('credential', () => {
    const namespace = 'default'

    let api
    let appStore
    let authzStore
    let cloudProfileStore
    let gardenerExtensionStore
    let credentialStore

    beforeEach(async () => {
      setActivePinia(createPinia())
      api = useApi()
      vi.spyOn(api, 'getCloudProviderCredentials')
      vi.spyOn(api, 'createCloudProviderCredential')
      vi.spyOn(api, 'updateCloudProviderCredential')
      vi.spyOn(api, 'deleteCloudProviderCredential')
      appStore = useAppStore()
      vi.spyOn(appStore, 'setSuccess')
      authzStore = useAuthzStore()
      authzStore.setNamespace(namespace)
      cloudProfileStore = useCloudProfileStore()
      cloudProfileStore.list = [
        {
          metadata: {
            providerType: 'aws',
          },
        },
        {
          metadata: {
            providerType: 'azure',
          },
        },
        {
          metadata: {
            providerType: 'gcp',
          },
        },
      ]
      gardenerExtensionStore = useGardenerExtensionStore()
      gardenerExtensionStore.list = [{
        resources: [
          {
            kind: 'DNSRecord',
            type: 'aws-route53',
            primary: true,
          },
        ],
      }]
      credentialStore = useCredentialStore()
      credentialStore.cloudProviderCredentials = {
        quotas: [
          ...quotas,
        ],
        secrets: [
          ...fixtures.credentials.secrets,
          ...secrets,
        ],
        secretBindings: [
          ...fixtures.credentials.secretBindings,
          ...secretBindings,
        ],
      }
    })

    afterEach(() => {
      appStore.setSuccess.mockClear()
      api.getCloudProviderCredentials.mockClear()
      api.createCloudProviderCredential.mockClear()
      api.updateCloudProviderCredential.mockClear()
      api.deleteCloudProviderCredential.mockClear()
    })

    it('should create a new credential store', () => {
      expect(credentialStore.isInitial).toBe(false)
      expect(cloudProfileStore.sortedProviderTypeList).toEqual(['aws', 'azure', 'gcp'])
    })
  })
})

@@ -48,28 +48,39 @@ export function getConfiguration () {
return getResource('/api/config')
}

/* CloudProviders Secrets */
/* Credentials */
function invokeCloudProviderCredentialMethod (method, params) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this method is sufficient

@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 3, 2024
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 3, 2024
- Improved SecretDat composable
- Added tests for credential store
Copy link

gitguardian bot commented Dec 10, 2024

⚠️ GitGuardian has uncovered 3 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
14824536 Triggered Generic High Entropy Secret c792b6f frontend/fixtures/credentials.js View secret
14824537 Triggered Generic High Entropy Secret c792b6f frontend/tests/stores/credential.spec.js View secret
14824538 Triggered Generic High Entropy Secret c792b6f frontend/tests/stores/credential.spec.js View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) needs/review Needs review needs/second-opinion Needs second review by someone else size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants