generator_acr.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package v1alpha1
  13. import (
  14. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  15. "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  16. smmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
  17. )
  18. // ACRAccessTokenSpec defines how to generate the access token
  19. // e.g. how to authenticate and which registry to use.
  20. // see: https://github.com/Azure/acr/blob/main/docs/AAD-OAuth.md#overview
  21. type ACRAccessTokenSpec struct {
  22. Auth ACRAuth `json:"auth"`
  23. // TenantID configures the Azure Tenant to send requests to. Required for ServicePrincipal auth type.
  24. TenantID string `json:"tenantId,omitempty"`
  25. // the domain name of the ACR registry
  26. // e.g. foobarexample.azurecr.io
  27. ACRRegistry string `json:"registry"`
  28. // Define the scope for the access token, e.g. pull/push access for a repository.
  29. // if not provided it will return a refresh token that has full scope.
  30. // Note: you need to pin it down to the repository level, there is no wildcard available.
  31. //
  32. // examples:
  33. // repository:my-repository:pull,push
  34. // repository:my-repository:pull
  35. //
  36. // see docs for details: https://docs.docker.com/registry/spec/auth/scope/
  37. // +optional
  38. Scope string `json:"scope,omitempty"`
  39. // EnvironmentType specifies the Azure cloud environment endpoints to use for
  40. // connecting and authenticating with Azure. By default it points to the public cloud AAD endpoint.
  41. // The following endpoints are available, also see here: https://github.com/Azure/go-autorest/blob/main/autorest/azure/environments.go#L152
  42. // PublicCloud, USGovernmentCloud, ChinaCloud, GermanCloud
  43. // +kubebuilder:default=PublicCloud
  44. EnvironmentType v1beta1.AzureEnvironmentType `json:"environmentType,omitempty"`
  45. }
  46. type ACRAuth struct {
  47. // ServicePrincipal uses Azure Service Principal credentials to authenticate with Azure.
  48. // +optional
  49. ServicePrincipal *AzureACRServicePrincipalAuth `json:"servicePrincipal,omitempty"`
  50. // ManagedIdentity uses Azure Managed Identity to authenticate with Azure.
  51. // +optional
  52. ManagedIdentity *AzureACRManagedIdentityAuth `json:"managedIdentity,omitempty"`
  53. // WorkloadIdentity uses Azure Workload Identity to authenticate with Azure.
  54. // +optional
  55. WorkloadIdentity *AzureACRWorkloadIdentityAuth `json:"workloadIdentity,omitempty"`
  56. }
  57. type AzureACRServicePrincipalAuth struct {
  58. SecretRef AzureACRServicePrincipalAuthSecretRef `json:"secretRef"`
  59. }
  60. type AzureACRManagedIdentityAuth struct {
  61. // If multiple Managed Identity is assigned to the pod, you can select the one to be used
  62. IdentityID string `json:"identityId,omitempty"`
  63. }
  64. type AzureACRWorkloadIdentityAuth struct {
  65. // ServiceAccountRef specified the service account
  66. // that should be used when authenticating with WorkloadIdentity.
  67. // +optional
  68. ServiceAccountRef *smmeta.ServiceAccountSelector `json:"serviceAccountRef,omitempty"`
  69. }
  70. // Configuration used to authenticate with Azure using static
  71. // credentials stored in a Kind=Secret.
  72. type AzureACRServicePrincipalAuthSecretRef struct {
  73. // The Azure clientId of the service principle used for authentication.
  74. ClientID smmeta.SecretKeySelector `json:"clientId,omitempty"`
  75. // The Azure ClientSecret of the service principle used for authentication.
  76. ClientSecret smmeta.SecretKeySelector `json:"clientSecret,omitempty"`
  77. }
  78. // ACRAccessToken returns a Azure Container Registry token
  79. // that can be used for pushing/pulling images.
  80. // Note: by default it will return an ACR Refresh Token with full access
  81. // (depending on the identity).
  82. // This can be scoped down to the repository level using .spec.scope.
  83. // In case scope is defined it will return an ACR Access Token.
  84. //
  85. // See docs: https://github.com/Azure/acr/blob/main/docs/AAD-OAuth.md
  86. //
  87. // +kubebuilder:object:root=true
  88. // +kubebuilder:storageversion
  89. // +kubebuilder:subresource:status
  90. // +kubebuilder:metadata:labels="external-secrets.io/component=controller"
  91. // +kubebuilder:resource:scope=Namespaced,categories={acraccesstoken},shortName=acraccesstoken
  92. type ACRAccessToken struct {
  93. metav1.TypeMeta `json:",inline"`
  94. metav1.ObjectMeta `json:"metadata,omitempty"`
  95. Spec ACRAccessTokenSpec `json:"spec,omitempty"`
  96. }
  97. // +kubebuilder:object:root=true
  98. // ACRAccessTokenList contains a list of ExternalSecret resources.
  99. type ACRAccessTokenList struct {
  100. metav1.TypeMeta `json:",inline"`
  101. metav1.ListMeta `json:"metadata,omitempty"`
  102. Items []ACRAccessToken `json:"items"`
  103. }