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

Support Azure blob as source #156

Merged
merged 27 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
07de03b
Copied folder from swagger spec PR check
summerhasama Jul 29, 2022
c16449c
enable new version 2022-07-01
summerhasama Jul 18, 2022
15b20d0
support azure blob as source and add validation
summerhasama Jul 22, 2022
14e2516
Fix indentation
summerhasama Jul 22, 2022
1f23e33
change version
summerhasama Jul 26, 2022
b6c1067
Fix incorrect naming
summerhasama Jul 26, 2022
ef67871
Add to error messages
summerhasama Jul 27, 2022
ff48420
fix managed identity for azblob
summerhasama Jul 29, 2022
e973eec
remove sas token and fix help messages
summerhasama Jul 29, 2022
44f1b2c
fix validator test
summerhasama Jul 29, 2022
e18a944
Provide shorthand params
summerhasama Jul 29, 2022
21cf4df
Merge branch 'k8s-configuration' into support-azure-blob-k8s-config
summerhasama Aug 3, 2022
6549481
Merge branch 'k8s-configuration' into support-azure-blob-k8s-config
bavneetsingh16 Aug 19, 2022
c757486
use older api version for sourceControlConfiguration
Aug 19, 2022
35ce5e1
add sastoken support
Sep 13, 2022
1e8a230
add sas token in error stmt
Sep 13, 2022
1a63578
add test case for blobStorage - Account Key
Sep 20, 2022
3dc3ed4
increase max retry attempts
Sep 20, 2022
172e87c
use latest api version for sourceControlConfiguration
Sep 21, 2022
b88e2fc
test cases changes
Sep 21, 2022
af136be
change to provisioningState
Sep 21, 2022
27d3839
add test case for sasToken
Sep 21, 2022
6b68b67
add testcase for sp with client secret
Sep 21, 2022
ffea1f2
add test for ManagedIdentity
Sep 21, 2022
934e09c
changes suggested for auth errors
Sep 28, 2022
8cd888f
fix the validation tests
Sep 28, 2022
a2df3ae
fix validation test for sp
Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/k8s-configuration/azext_k8s_configuration/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@
--kind bucket --url https://bucket-provider.minio.io \\
--bucket-name my-bucket --kustomization name=my-kustomization \\
--bucket-access-key my-access-key --bucket-secret-key my-secret-key
- name: Create a Kubernetes v2 Flux Configuration with Azure Blob Source Kind
text: |-
az k8s-configuration flux create --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters \\
--name myconfig --scope cluster --namespace my-namespace \\
--kind azblob --url https://mystorageaccount.blob.core.windows.net \\
--container-name my-container --kustomization name=my-kustomization \\
--account-key my-account-key
"""

helps[
Expand All @@ -108,11 +116,16 @@
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
--url https://github.com/Azure/arc-k8s-demo --branch main \\
--kustomization name=my-kustomization path=./my/new-path
- name: Update a Flux v2 Kubernetse configuration with Bucket Source Kind to connect insecurely
- name: Update a Flux v2 Kubernetes configuration with Bucket Source Kind to connect insecurely
text: |-
az k8s-configuration flux update --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
--bucket-insecure
- name: Update a Flux v2 Kubernetes configuration with Azure Blob Source Kind with another container name
text: |-
az k8s-configuration flux update --resource-group my-resource-group \\
--cluster-name mycluster --cluster-type connectedClusters --name myconfig \\
--container-name other-container
"""

helps[
Expand Down
58 changes: 57 additions & 1 deletion src/k8s-configuration/azext_k8s_configuration/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def load_arguments(self, _):
)
c.argument(
"kind",
arg_type=get_enum_type([consts.GIT, consts.BUCKET]),
arg_type=get_enum_type([consts.GIT, consts.BUCKET, consts.AZBLOB]),
help="Source kind to reconcile",
)
c.argument(
Expand Down Expand Up @@ -178,6 +178,62 @@ def load_arguments(self, _):
help="Define kustomizations to sync sources with parameters ['name', 'path', 'depends_on', 'timeout', 'sync_interval', 'retry_interval', 'prune', 'force']",
nargs="+",
)
c.argument(
"container_name",
help="Name of the Azure Blob Storage container to sync",
bavneetsingh16 marked this conversation as resolved.
Show resolved Hide resolved
)
c.argument(
"sp_client_id",
arg_group="Azure Blob Auth",
options_list=["--sp-client-id", "--service-principal-client-id"],
help="The client ID for authenticating a service principal with Azure Blob, required for this authentication method",
)
c.argument(
"sp_tenant_id",
arg_group="Azure Blob Auth",
options_list=["--sp-tenant-id", "--service-principal-tenant-id"],
help="The tenant ID for authenticating a service principal with Azure Blob, required for this authentication method",
)
c.argument(
"sp_client_secret",
arg_group="Azure Blob Auth",
options_list=["--sp-client-secret", "--service-principal-client-secret"],
help="The client secret for authenticating a service principal with Azure Blob",
)
c.argument(
"sp_client_cert",
arg_group="Azure Blob Auth",
options_list=["--sp-client-cert", "--service-principal-client-certificate"],
help="The Base64 encoded client certificate for authenticating a service principal with Azure Blob",
)
c.argument(
"sp_client_cert_password",
arg_group="Azure Blob Auth",
options_list=["--sp-cert-password", "--service-principal-client-certificate-password"],
help="The password for the client certificate used to authenticate a service principal with Azure Blob",
)
c.argument(
"sp_client_cert_send_chain",
arg_group="Azure Blob Auth",
options_list=["--sp-cert-send-chain", "--service-principal-client-certificate-send-chain"],
help="Specifies whether to include x5c header in client claims when acquiring a token to enable subject name / issuer based authentication for the client certificate",
)
c.argument(
"account_key",
arg_group="Azure Blob Auth",
help="The Azure Blob Shared Key for authentication ",
)
c.argument(
"sas_token",
arg_group="Azure Blob Auth",
help="The Azure Blob SAS Token for authentication ",
)
c.argument(
"mi_client_id",
arg_group="Azure Blob Auth",
options_list=["--mi-client-id", "--managed-identity-client-id"],
help="The client ID of the managed identity for authentication with Azure Blob",
)

with self.argument_context("k8s-configuration flux update") as c:
c.argument(
Expand Down
51 changes: 48 additions & 3 deletions src/k8s-configuration/azext_k8s_configuration/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
# API VERSIONS -----------------------------------------

SOURCE_CONTROL_API_VERSION = "2022-03-01"
FLUXCONFIG_API_VERSION = "2022-03-01"
EXTENSION_API_VERSION = "2022-03-01"
FLUXCONFIG_API_VERSION = "2022-07-01"
EXTENSION_API_VERSION = "2022-07-01"

# ERROR/HELP TEXT DEFINITIONS -----------------------------------------

Expand Down Expand Up @@ -41,7 +41,30 @@
REQUIRED_BUCKET_VALUES_MISSING_HELP = (
"Provide either both of '--secret-key' and '--access-key' or '--local-auth-ref'"
)

REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_VALUES_MISSING_ERROR = (
bavneetsingh16 marked this conversation as resolved.
Show resolved Hide resolved
"Error! Service principal is invalid because it is missing value(s)"
)
REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_VALUES_MISSING_HELP = (
"Provide '--sp-client-id', '--sp-tenant-id', and either '--sp-client-secret' or '--sp-client-cert'"
)
REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_AUTH_ERROR = (
"Error! Too many authentication methods provided for service principal"
)
REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_AUTH_HELP = (
"Provide either '--sp-client-secret' or '--sp-client-cert'"
)
REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_CERT_VALUES_MISSING_ERROR = (
"Error! Service principal certificate password is invalid"
)
REQUIRED_AZURE_BLOB_SERVICE_PRINCIPAL_CERT_VALUES_MISSING_HELP = (
"Provide '--sp-client-id', '--sp-tenant-id', and '--sp-client-cert' with your '--sp-cert-password"
)
REQUIRED_AZURE_BLOB_AUTH_ERROR = (
"Error! Too many authentication methods provided for Azure Blob"
)
REQUIRED_AZURE_BLOB_AUTH_HELP = (
"Specify one of the available authentication methods from the list: '--local-auth-ref', '--account-key', '--sas-token', '--mi-client-id', or service principal with '--sp-client-id', '--sp-tenant-id', and either '--sp-client-secret' or '--sp-client-cert'"
)
EXTRA_VALUES_PROVIDED_ERROR = (
"Error! Invalid properties [{}] were specified for kind '{}'"
)
Expand Down Expand Up @@ -213,6 +236,24 @@
"local_auth_ref",
}

AZUREBLOB_REQUIRED_PARAMS = {"url", "container_name"}
AZUREBLOB_VALID_PARAMS = {
"url",
"container_name",
"sync_interval",
"timeout",
"account_key",
"local_auth_ref",
"sp_tenant_id",
"sp_client_id",
"sp_client_cert",
"sp_client_cert_password",
"sp_client_secret",
"sp_client_cert_send_chain",
"sas_token",
"mi_client_id",
}

DEPENDENCY_KEYS = ["dependencies", "depends_on", "dependsOn", "depends"]
SYNC_INTERVAL_KEYS = ["interval", "sync_interval", "syncInterval"]
RETRY_INTERVAL_KEYS = ["retryInterval", "retry_interval"]
Expand All @@ -222,12 +263,16 @@
VALID_DURATION_REGEX = r"((?P<hours>\d+?)h)?((?P<minutes>\d+?)m)?((?P<seconds>\d+?)s)?"
VALID_GIT_URL_REGEX = r"^(((http|https|ssh)://)|(git@))"
VALID_BUCKET_URL_REGEX = r"^(((http|https)://))"
VALID_AZUREBLOB_URL_REGEX = r"^(((http|https)://))"

VALID_KUBERNETES_DNS_SUBDOMAIN_NAME_REGEX = r"^[a-z0-9]([\.\-a-z0-9]*[a-z0-9])?$"
VALID_KUBERNETES_DNS_NAME_REGEX = r"^[a-z0-9]([\-a-z0-9]*[a-z0-9])?$"

GIT = "git"
BUCKET = "bucket"
BUCKET_CAPS = "Bucket"
AZBLOB = "azblob"
AZURE_BLOB = "AzureBlob"
GIT_REPOSITORY = "GitRepository"

CONNECTED_CLUSTER_TYPE = "connectedclusters"
Expand Down
Loading