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

kube_encryption_resources must be output as yaml #6309

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

mirwan
Copy link
Contributor

@mirwan mirwan commented Jun 22, 2020

What type of PR is this?
/kind bug

What this PR does / why we need it:
kube_encryption_resources variable (list) is rendered as plain text from secrets_encryption.yaml.j2 template, elements of this list (strings) are prefixed with unicode "u" prefix in the rendered manifest.
As a consequence, encryption at REST is simply ignored for these resources.

This variable must be serialized as yaml, that's what this PR does.

Which issue(s) this PR fixes:
None

Special notes for your reviewer:
N/A

Does this PR introduce a user-facing change?:

Once the encryption-at-rest is in place, resources must be updated.
As mentioned in https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/, for example with secrets only (as the default value of `kube_encryption_resources` variable is), the following command should be applied:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jun 22, 2020
@k8s-ci-robot k8s-ci-robot requested review from floryut and holmsten June 22, 2020 12:55
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mirwan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jun 22, 2020
@floryut
Copy link
Member

floryut commented Jun 23, 2020

I'm not sure this is needed, here is an output of what I got as of now

[root@instance-1 ssl]# cat secrets_encryption.yaml
kind: EncryptionConfig
apiVersion: v1
resources:
  - resources: ['secrets']
    providers:
    - aescbc:
        keys:
        - name: key
          secret: aGg2TUtSZTllUUpGRlFhalR0d050UzdQMTFLand2SDI=
    - identity: {}

Compared to your version

[root@instance-1 ssl]# cat secrets_encryption.yaml
kind: EncryptionConfig
apiVersion: v1
resources:
  - resources: 
    - 'secrets'

    providers:
    - aescbc:
        keys:
        - name: key
          secret: aGg2TUtSZTllUUpGRlFhalR0d050UzdQMTFLand2SDI=
    - identity: {}

Am I missing something ?

@mirwan
Copy link
Contributor Author

mirwan commented Jun 23, 2020

@floryut That is the output I get:

kind: EncryptionConfig
apiVersion: v1
resources:
  - resources: [u'secrets']
    providers:
    - aescbc:
        keys:
        - name: key
          secret: 5oM3SecretB643ncoded=
    - identity: {}

I don't know what is the root cause (py version on the remote host, control machine, ...).
Anyway, as far as the variable kube_encryption_resources is defined as an ansible (python) list it should be serialized as yaml.
Otherwise, kube_encryption_resources type may be enforced as string but it could be handy to keep it as a list.

@mirwan
Copy link
Contributor Author

mirwan commented Jun 24, 2020

@floryut What do you think ?

@floryut
Copy link
Member

floryut commented Jun 24, 2020

@floryut What do you think ?

Looks good to me, WDYT @EppO ?

@Miouge1
Copy link
Contributor

Miouge1 commented Jun 24, 2020

Can we add a test case for it? Like a file in tests/files/*.yml with an working example of kube_encryption_resources?

@floryut
Copy link
Member

floryut commented Jun 24, 2020

Can we add a test case for it? Like a file in tests/files/*.yml with an working example of kube_encryption_resources?

Well as of now we kind of already have a test for it as it's default to kube_encryption_resources: [secrets]
Do you think we need more than that ?

@floryut
Copy link
Member

floryut commented Jun 26, 2020

Lets merge that, we can always add another PR if we want to further test things, as long as this fix a bug in some cases
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 26, 2020
@k8s-ci-robot k8s-ci-robot merged commit d3ca9d1 into kubernetes-sigs:master Jun 26, 2020
@mirwan
Copy link
Contributor Author

mirwan commented Jun 26, 2020

@floryut Thx for the approval.
@Miouge1 @floryut I can work on another PR to include a encryption test. I took a look at the current test cases, I would add a 0X0_check_encryption.yml playbook with a block task conditioned by kube_encrypt_secret_data. The playbook would be run no matter what but tasks would be skipped most of the time. Is it the right way ?

LuckySB pushed a commit to southbridgeio/kubespray that referenced this pull request Jun 29, 2020
erulabs added a commit to kubesail/kubespray that referenced this pull request Jun 30, 2020
* 'master' of https://github.com/kubernetes-sigs/kubespray: (22 commits)
  Remove runtime-config from kubeadm if empty (kubernetes-sigs#6311)
  Update deprecated api (kubernetes-sigs#6245)
  Update kube-router to 1.0.0 (kubernetes-sigs#6211)
  Fix kubelet cgroup driver detection for crio (kubernetes-sigs#6331)
  Update hashes and set default version to 1.18.5 (kubernetes-sigs#6335)
  Change MetalLB to one of addons (kubernetes-sigs#6238)
  Update calico to 1.15.0 + minor update to kube-ovn/weave (kubernetes-sigs#6306)
  Add .editorconfig file (kubernetes-sigs#6307)
  Use NetworkManager to manage resolv.conf in FedoraCoreOS (kubernetes-sigs#6291)
  Add USE_REAL_HOSTNAME to inventory.py (kubernetes-sigs#6293)
  Cleanup OpenStack network things (kubernetes-sigs#6283)
  Add support for dns_etchosts (kubernetes-sigs#6236)
  kube_encryption_resources must be output as yaml (kubernetes-sigs#6309)
  Gather ansible_default_ipv4 for specific groups (kubernetes-sigs#6318)
  added azure_cloud parameter to Azure's cloud_config (kubernetes-sigs#6321)
  Fix some doc links (kubernetes-sigs#6328)
  Use `connection: local` when `delegate_to: localhost` (kubernetes-sigs#6322)
  Add /dev volume (kubernetes-sigs#6319)
  Update cilium to 1.8.0 (kubernetes-sigs#6314)
  fix use of ansible tags (kubernetes-sigs#6316)
  ...
@brysonshepherd
Copy link

brysonshepherd commented Aug 19, 2020

@mirwan thanks for this. it was weird because new clusters were fine, but it was killing my upgrades.

@brysonshepherd
Copy link

We need this cherrypicked to release-2.13

@floryut
Copy link
Member

floryut commented Aug 20, 2020

We need this cherrypicked to release-2.13

Please do, we could always do another tag with the 1.18.9 I guess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants