Skip to content

Commit 31ffe1f

Browse files
mrsiejassmguggen
authored andcommitted
fix: KubectlHandler - insecure kubeconfig warning (aws#16063)
KubectlHandler started to return insecure kubeconfig file warning starting Kubernetes 1.20 ``` 2:08:24 PM | CREATE_FAILED | Custom::AWSCDK-EKS-HelmChart | NginxIngressController/Resource/Default Received response status [FAILED] from custom resource. Message returned: Error: b'WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /tmp/kubeconfig\nWARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /tmp/kubeconfig\nError: UPGRADE FAILED: an other operation (install/upgrade/rollback) is in progress\n' ``` Fix changes permissions of the file to read and write for the User and removes permissions for Group and Others. Fixes aws#14560 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a0625c5 commit 31ffe1f

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

packages/@aws-cdk/aws-eks/lib/kubectl-handler/apply/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
outdir = os.environ.get('TEST_OUTDIR', '/tmp')
1313
kubeconfig = os.path.join(outdir, 'kubeconfig')
1414

15+
1516
def apply_handler(event, context):
1617
logger.info(json.dumps(event))
1718

@@ -35,6 +36,9 @@ def apply_handler(event, context):
3536
logger.info(f'Running command: {cmd}')
3637
subprocess.check_call(cmd)
3738

39+
if os.path.isfile(kubeconfig):
40+
os.chmod(kubeconfig, 0o600)
41+
3842
# write resource manifests in sequence: { r1 }{ r2 }{ r3 } (this is how
3943
# a stream of JSON objects can be included in a k8s manifest).
4044
manifest_list = json.loads(manifest_text)

packages/@aws-cdk/aws-eks/lib/kubectl-handler/get/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
outdir = os.environ.get('TEST_OUTDIR', '/tmp')
1414
kubeconfig = os.path.join(outdir, 'kubeconfig')
1515

16+
1617
def get_handler(event, context):
1718
logger.info(json.dumps(event))
1819

@@ -30,6 +31,9 @@ def get_handler(event, context):
3031
'--kubeconfig', kubeconfig
3132
])
3233

34+
if os.path.isfile(kubeconfig):
35+
os.chmod(kubeconfig, 0o600)
36+
3337
object_type = props['ObjectType']
3438
object_name = props['ObjectName']
3539
object_namespace = props['ObjectNamespace']

packages/@aws-cdk/aws-eks/lib/kubectl-handler/helm/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
outdir = os.environ.get('TEST_OUTDIR', '/tmp')
1313
kubeconfig = os.path.join(outdir, 'kubeconfig')
1414

15+
1516
def helm_handler(event, context):
1617
logger.info(json.dumps(event))
1718

@@ -38,6 +39,9 @@ def helm_handler(event, context):
3839
'--kubeconfig', kubeconfig
3940
])
4041

42+
if os.path.isfile(kubeconfig):
43+
os.chmod(kubeconfig, 0o600)
44+
4145
# Write out the values to a file and include them with the install and upgrade
4246
values_file = None
4347
if not request_type == "Delete" and not values_text is None:

packages/@aws-cdk/aws-eks/lib/kubectl-handler/patch/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
outdir = os.environ.get('TEST_OUTDIR', '/tmp')
1313
kubeconfig = os.path.join(outdir, 'kubeconfig')
1414

15+
1516
def patch_handler(event, context):
1617
logger.info(json.dumps(event))
1718

@@ -29,6 +30,9 @@ def patch_handler(event, context):
2930
'--kubeconfig', kubeconfig
3031
])
3132

33+
if os.path.isfile(kubeconfig):
34+
os.chmod(kubeconfig, 0o600)
35+
3236
resource_name = props['ResourceName']
3337
resource_namespace = props['ResourceNamespace']
3438
apply_patch_json = props['ApplyPatchJson']

0 commit comments

Comments
 (0)