Skip to content

Add relabel option to secrets #1210

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions newsfragments/secret-selinux-relabel-option.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add relabel option to secret to make possible to read the secret file by the contained process.
11 changes: 10 additions & 1 deletion podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ def get_secret_args(compose, cnt, secret, podman_is_building=False):
declared_secret = compose.declared_secrets[secret_name]

source_file = declared_secret.get("file")
secret_relabel = declared_secret.get("relabel")
dest_file = ""
secret_opts = ""

Expand Down Expand Up @@ -624,7 +625,15 @@ def get_secret_args(compose, cnt, secret, podman_is_building=False):
dest_file = f"/run/secrets/{sec}"
else:
dest_file = secret_target
volume_ref = ["--volume", f"{source_file}:{dest_file}:ro,rprivate,rbind"]

mount_options = 'ro,rprivate,rbind'
if secret_relabel not in set(("z", "Z", None)):
raise ValueError(
f'ERORR: Run secret "{secret_name} has invalid "relabel" option '
+ f'"{secret_relabel}". Expected "Z" "z" or nothing.')
if secret_relabel:
mount_options = f'{mount_options},{secret_relabel}'
volume_ref = ["--volume", f"{source_file}:{dest_file}:{mount_options}"]

if secret_uid or secret_gid or secret_mode:
sec = secret_target if secret_target else secret_name
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_container_to_args_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ async def test_secret_target_matches_secret_name_secret_type_not_env(self):
"file_secret",
repo_root() + "/test_dirname/my_secret:/run/secrets/file_secret:ro,rprivate,rbind",
),
(
"relabel",
{
"file_secret": {
"file": "./my_secret",
"relabel": "Z"
}
},
"file_secret",
repo_root() + "/test_dirname/my_secret:/run/secrets/file_secret:ro,rprivate,rbind,Z",
),
(
"custom_target_name",
{
Expand Down
Loading