Skip to content

Conversation

bpradipt
Copy link
Contributor

The earlier implementation relied on using a specific mount-path prefix - /sealed to determine that the referenced secret is a sealed secret. However that was restrictive for certain use cases as it forced the user to always use a specific mountpath naming convention.

This commit introduces an alternative implementation to relax the restriction. A sealed secret can be mounted in any mount-path. However it comes with a potential performance penality. The implementation loops through all volume mounts and reads the file to determine if it's a sealed secret or not.

Fixes: #10398

@katacontainersbot katacontainersbot added the size/small Small and simple task label Dec 18, 2024
@bpradipt
Copy link
Contributor Author

@stevenhorsman @fitzthum @Xynnn007 @ChengyuZhu6 @sprt I made an attempt to remove the mount path prefix restriction for sealed_secret as volume. Raising a draft PR to get your feedback on the approach and if is a better alternative to try out.

@bpradipt bpradipt marked this pull request as ready for review December 18, 2024 16:18
Copy link
Contributor

@Apokleos Apokleos left a comment

Choose a reason for hiding this comment

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

Thx @bpradipt I just have an idea that about introducing a method to handle this checking logic. but It almost looks good to me.

@bpradipt bpradipt self-assigned this Dec 19, 2024
@katacontainersbot katacontainersbot added size/large Task of significant size and removed size/small Small and simple task labels Dec 22, 2024
@bpradipt bpradipt requested a review from Apokleos December 23, 2024 12:25
Copy link
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

Thanks @bpradipt ! I think this approach is likely to improve usability and looks good to me. Just two minor comments:

  1. The unrelated file to be unsealed may lead to confusion in logging.
  2. We may need to update the test case of sealedsecret in ci at the same time.

@bpradipt
Copy link
Contributor Author

bpradipt commented Jan 8, 2025

2. We may need to update the test case of sealedsecret in ci at the same time.

The example test pods uses the following mountpath and I don't think we need to change this. Let me know if you think otherwise and I'll change it to some other path..

        - name: sealed-secret-volume
           mountPath: "/sealed/secret-value"
        - name: not-sealed-secret-volume
           mountPath: "/sealed/not-sealed-secret-value"

Copy link
Contributor

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

I think this approach is fine. It's a little weird to check each file to see if it is sealed, but I guess it only scales with the total number of mounts.

Copy link
Contributor

@fitzthum fitzthum left a comment

Choose a reason for hiding this comment

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

LGTM

@bpradipt
Copy link
Contributor Author

The sealed secret CI tests for both env and file are failing.
The error points to issues with base64 decoding of the secret

Caused by: parse SealedSecret failed: base64 decode Secret body

This error comes from unseal_secret function in confidential-data-hub/secret/src/lib.rs to validate the input.

I checked the sealed secret input in the CI and it's proper.

sealed.fakejwsheader.ewogICAgInZlcnNpb24iOiAiMC4xLjAiLAogICAgInR5cGUiOiAidmF1bHQiLAogICAgIm5hbWUiOiAia2JzOi8vL2RlZmF1bHQvc2VhbGVkLXNlY3JldC90ZXN0IiwKICAgICJwcm92aWRlciI6ICJrYnMiLAogICAgInByb3ZpZGVyX3NldHRpbmdzIjoge30sCiAgICAiYW5ub3RhdGlvbnMiOiB7fQp9Cg==.fakesignature

Looking for ideas where to look at next to root cause this issue..

@stevenhorsman @fitzthum @ChengyuZhu6 or anyone ..

The earlier implementation relied on using a specific mount-path prefix - `/sealed`
to determine that the referenced secret is a sealed secret.
However that was restrictive for certain use cases as it forced
the user to always use a specific mountpath naming convention.

This commit introduces an alternative implementation to relax the
restriction. A sealed secret can be mounted in any mount-path.
However it comes with a potential performance penality. The
implementation loops through all volume mounts and reads the file
to determine if it's a sealed secret or not.

Fixes: kata-containers#10398

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
@stevenhorsman
Copy link
Member

stevenhorsman commented Jan 13, 2025

Sorry for the stupid question here, but just thinking about the env test that is failing first:

  • In the CI we are seeing:
vmconsole="{\"msg\":\"Calling unseal_file for - source: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value\\\" destination: \\\"/sealed/secret-value\\\"\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818201552Z\",\"subsystem\":\"rpc\",\"source\":\"agent\",\"name\":\"kata-agent\",\"version\":\"0.1.0\",\"pid\":\"143\"}"
 vmconsole="{\"msg\":\"skipping sealed source entry DirEntry(\\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\") because its file type is FileType(FileType { mode: 16384 })\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818264576Z\",\"source\":\"agent\",\"version\":\"0.1.0\",\"pid\":\"143\",\"name\":\"kata-agent\",\"subsystem\":\"cdh\"}"
vmconsole="{\"msg\":\"sealed source entry target path: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\"\",\"level\":\"INFO\",\"ts\":\"2025-01-13T06:21:46.818320456Z\",\"name\":\"kata-agent\",\"source\":\"agent\",\"pid\":\"143\",\"subsystem\":\"cdh\",\"version\":\"0.1.0\"}"
vmconsole="{\"msg\":\"sealed source is not a file: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\"\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818629772Z\",\"source\":\"agent\",\"pid\":\"143\",\"name\":\"kata-agent\",\"subsystem\":\"cdh\",\"version\":\"0.1.0\"}"
vmconsole="{\"msg\":\"sealed source entry target path: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162/secret\\\"\",\"level\":\"INFO\",\"ts\":\"2025-01-13T06:21:46.818658179Z\",\"source\":\"agent\",\"subsystem\":\"cdh\",\"name\":\"kata-agent\",\"version\":\"0.1.0\",\"pid\":\"143\"}"
vmconsole="\x1b[90m[\x1b[0m2025-01-13T06:21:46Z \x1b[32mINFO \x1b[0m confidential_data_hub::hub\x1b[90m]\x1b[0m unseal secret called"
vmconsole="\x1b[90m[\x1b[0m2025-01-13T06:21:46Z \x1b[1m\x1b[31mERROR\x1b[0m ttrpc_cdh::ttrpc_server\x1b[90m]\x1b[0m [ttRPC CDH] UnsealSecret :"
vmconsole="    unseal secret failed"
vmconsole="    Caused by: parse SealedSecret failed: base64 decode Secret body"

But your new debug code is in the unseal_file path, not the unsealed_env, so I'm not sure if we'd expect this to work?

For the sealed file test, we seem to get the same response:

  • The sealed_secret looks like sealed.fakejwsheader.ewogICAgInZlcnNpb24iOiAiMC4xLjAiLAogICAgInR5cGUiOiAidmF1bHQiLAogICAgIm5hbWUiOiAia2JzOi8vL2RlZmF1bHQvc2VhbGVkLXNlY3JldC90ZXN0IiwKICAgICJwcm92aWRlciI6ICJrYnMiLAogICAgInByb3ZpZGVyX3NldHRpbmdzIjoge30sCiAgICAiYW5ub3RhdGlvbnMiOiB7fQp9Cg==.fakesignature
  • The logs show:
vmconsole="{\"msg\":\"Calling unseal_file for - source: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value\\\" destination: \\\"/sealed/secret-value\\\"\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818201552Z\",\"subsystem\":\"rpc\",\"source\":\"agent\",\"name\":\"kata-agent\",\"version\":\"0.1.0\",\"pid\":\"143\"}"
vmconsole="{\"msg\":\"skipping sealed source entry DirEntry(\\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\") because its file type is FileType(FileType { mode: 16384 })\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818264576Z\",\"source\":\"agent\",\"version\":\"0.1.0\",\"pid\":\"143\",\"name\":\"kata-agent\",\"subsystem\":\"cdh\"}"
vmconsole="{\"msg\":\"sealed source entry target path: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\"\",\"level\":\"INFO\",\"ts\":\"2025-01-13T06:21:46.818320456Z\",\"name\":\"kata-agent\",\"source\":\"agent\",\"pid\":\"143\",\"subsystem\":\"cdh\",\"version\":\"0.1.0\"}"
vmconsole="{\"msg\":\"sealed source is not a file: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162\\\"\",\"level\":\"DEBG\",\"ts\":\"2025-01-13T06:21:46.818629772Z\",\"source\":\"agent\",\"pid\":\"143\",\"name\":\"kata-agent\",\"subsystem\":\"cdh\",\"version\":\"0.1.0\"}"
vmconsole="{\"msg\":\"sealed source entry target path: \\\"/run/kata-containers/shared/containers/6c40bfce284a4d90d56f17edbac493372881accc5d2647ee491a1b4bf3c0daff-c1c16822d73eeab8-secret-value/..2025_01_13_06_21_43.1841179162/secret\\\"\",\"level\":\"INFO\",\"ts\":\"2025-01-13T06:21:46.818658179Z\",\"source\":\"agent\",\"subsystem\":\"cdh\",\"name\":\"kata-agent\",\"version\":\"0.1.0\",\"pid\":\"143\"}"
vmconsole="\x1b[90m[\x1b[0m2025-01-13T06:21:46Z \x1b[32mINFO \x1b[0m confidential_data_hub::hub\x1b[90m]\x1b[0m unseal secret called"
vmconsole="\x1b[90m[\x1b[0m2025-01-13T06:21:46Z \x1b[1m\x1b[31mERROR\x1b[0m ttrpc_cdh::ttrpc_server\x1b[90m]\x1b[0m [ttRPC CDH] UnsealSecret :"
vmconsole="    unseal secret failed"
vmconsole="    Caused by: parse SealedSecret failed: base64 decode Secret body"

From the limited debug info we have here it looks like it's failing in the CDH:

        let sections: Vec<_> = secret.split('.').collect();

        if sections.len() != 4 {
            return Err(SecretError::ParseFailed("malformed input sealed secret"));
        }

        let secret_json = STANDARD
            .decode(sections[2])
            .map_err(|_| SecretError::ParseFailed("base64 decode Secret body"))?;

but if it's using the secret we'd expect, then the 3rd section (ewogICAgInZlcnNpb24iOiAiMC4xLjAiLAogICAgInR5cGUiOiAidmF1bHQiLAogICAgIm5hbWUiOiAia2JzOi8vL2RlZmF1bHQvc2VhbGVkLXNlY3JldC90ZXN0IiwKICAgICJwcm92aWRlciI6ICJrYnMiLAogICAgInByb3ZpZGVyX3NldHRpbmdzIjoge30sCiAgICAiYW5ub3RhdGlvbnMiOiB7fQp9Cg==.), does decode to

{
    "version": "0.1.0",
    "type": "vault",
    "name": "kbs:///default/sealed-secret/test",
    "provider": "kbs",
    "provider_settings": {},
    "annotations": {}
}

So I guess my conclusion is that we must be acting on a different secret then? I'm not sure how to get further with debug though - debugging in the guest-components has always been difficult/impossible :(

@bpradipt
Copy link
Contributor Author

@stevenhorsman from the logs - https://github.com/kata-containers/kata-containers/actions/runs/12726288825/job/35508106381?pr=10674 both the unsealed_env and unsealed_file tests are failing

not ok 2 Unseal Env Secrets with CDH
not ok 3 Unseal File Secrets with CDH

They both are failing.

From the logs at least it looks like the pod is using the correct secrets. But I can't be sure :-(

@stevenhorsman
Copy link
Member

@stevenhorsman from the logs - https://github.com/kata-containers/kata-containers/actions/runs/12726288825/job/35508106381?pr=10674 both the unsealed_env and unsealed_file tests are failing

not ok 2 Unseal Env Secrets with CDH not ok 3 Unseal File Secrets with CDH

They both are failing.

From the logs at least it looks like the pod is using the correct secrets. But I can't be sure :-(

Yeah my point was - should the unseal_file code be running on the env test?

@ChengyuZhu6
Copy link
Member

@bpradipt I think this issue might stem from the patch applied from CDH, as seen in this commit: confidential-containers/guest-components@8749486?

@ChengyuZhu6
Copy link
Member

I think we can resolve the issue by updating the encoded string of sealed secret in the ci.

@bpradipt
Copy link
Contributor Author

@bpradipt I think this issue might stem from the patch applied from CDH, as seen in this commit: confidential-containers/guest-components@8749486?

Great find @ChengyuZhu6 .. Let me try updating the encoded string values in ci

@stevenhorsman
Copy link
Member

Thanks for the help @ChengyuZhu6 - I'm still not clear why Pradipta's code changes would be the first thing to hit it? Any ideas why the nightly isn't failing as soon as we bumped the guest-components to pick up that patch?

@bpradipt
Copy link
Contributor Author

Thanks for the help @ChengyuZhu6 - I'm still not clear why Pradipta's code changes would be the first thing to hit it? Any ideas why the nightly isn't failing as soon as we bumped the guest-components to pick up that patch?

any likelihood of cached artefacts being used for the test cluster?

The existing encoding was base64 and it fails due to
confidential-containers/guest-components@8749486

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
Copy link
Member

@ChengyuZhu6 ChengyuZhu6 left a comment

Choose a reason for hiding this comment

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

LGTM thanks @bpradipt

Copy link
Member

@stevenhorsman stevenhorsman left a comment

Choose a reason for hiding this comment

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

I would still like to understand why we weren't getting failures with the guest-components bump PR (or nightly) if the encoding was the problem, but I don't think that should block this PR now the tests are passing

@ChengyuZhu6 ChengyuZhu6 merged commit 7d34ca4 into kata-containers:main Jan 14, 2025
291 of 299 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test size/large Task of significant size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exploring a more graceful solution to use Sealed Secret as volume
6 participants