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 aws ecs readonly_root_filesystem #27496

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NickLavrov
Copy link

@NickLavrov NickLavrov commented Feb 2, 2025

Summary & Motivation

When unset, readonlyRootFilesystem is false on ECS tasks, which then violates this Security Hub control

How I Tested These Changes

Not sure how to test ECS launching. I added an assertion to the existing pytest that this defaults to None, and added a new pytest that verifies a setting of true carries through to the task definition.

Changelog

Add optional boolean readonly_root_filesystem to container_context.

@NickLavrov NickLavrov marked this pull request as ready for review February 3, 2025 16:11
@NickLavrov NickLavrov requested a review from neverett as a code owner February 3, 2025 16:11
@gibsondan gibsondan self-requested a review February 3, 2025 16:12
Copy link
Member

@gibsondan gibsondan left a comment

Choose a reason for hiding this comment

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

@NickLavrov thanks for sending this out! Do you think its plausible that somebody would want to vary the value of this for different code locations within their deployment? Or would it always be a single setting that you put on the run launcher / agent in the dagster.yaml? Asking because if you don't need to vary it per code location, it doesn't need to go on EcsContainerContext

@NickLavrov
Copy link
Author

@gibsondan Personally I want this value to be true for all ecs tasks, per the AWS Security Hub control. I am not sure where someone would want this to be false, but I also don't really have that many use-cases so far with how we use Dagster, so I think leaving it configurable like this makes sense. I leave it defaulting to None to match existing behavior, also.

I'm not sure how to implement that other scenario, also. I just followed the pattern of repository_credentials more or less.

I also note all the CI tests are failing due to a docker pull error unrelated to my changes.

…n value when False. Update pytest for both true and false scenarios
Copy link
Member

@gibsondan gibsondan left a comment

Choose a reason for hiding this comment

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

nice, that's my intuition too. I think if that's the case we can simplify this a bit - removing it from the 'per-location configuration piece' and only referencing it in the run launcher instead of EcsContainerContext. That should be a strict subset of what you have now.

We'll get the CI fixed, we changed the image recently and just need to get it applied here too. Thanks for flagging that.

@@ -734,6 +741,7 @@ def _run_task_kwargs(
ephemeral_storage=container_context.run_resources.get("ephemeral_storage"),
volumes=container_context.volumes,
mount_points=container_context.mount_points,
readonly_root_filesystem=container_context.readonly_root_filesystem,
Copy link
Member

Choose a reason for hiding this comment

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

once this is just on the run launcher and not on EcsContainerContext, this can be self.readonly_root_filesystem instead

]
container_definition = task_definition["containerDefinitions"][0]

# Assert that readonlyRootFilesystem is set to correctly
Copy link

Choose a reason for hiding this comment

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

The comment readonlyRootFilesystem is set to correctly contains a grammatical error. Consider revising to readonlyRootFilesystem is set correctly.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines +133 to +140
"readonly_root_filesystem": Field(
BoolSource,
is_required=False,
description=(
"When true, the root filesystem of the container is read-only."
"See https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html"
),
),
Copy link
Member

Choose a reason for hiding this comment

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

configuration that just goes on the run launcher config and not in the per-location config goes here instead:

"task_definition_prefix": Field(
StringSource,
is_required=False,
default_value="run",
description=(
"A prefix that is applied to all task definitions created by the EcsRunLauncher. Defaults to 'run'."
),
),
- so you would just copy paste this same configuration to be there instead of in SHARED_ECS_SCHEMA.

Copy link
Author

@NickLavrov NickLavrov Feb 3, 2025

Choose a reason for hiding this comment

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

I commented out all instances of readonly_root_filesystem in container_context.py, moved that def to launcher.py, and changed the pytest to use:

    with instance_cm(
        {
            "task_definition": {
                "task_role_arn": "fake-task-role",
                "execution_role_arn": "fake-execution-role",
            },
            "readonly_root_filesystem": readonly_root_filesystem,
        }

Is this approach correct in general (i.e. is that the right way to have this test run?)? I think I will have to uncomment some instances of readonly_root_filesystem in container_context.py.

Copy link
Member

Choose a reason for hiding this comment

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

that looks right to me!

@mlarose
Copy link
Contributor

mlarose commented Feb 3, 2025

Not sure how to test ECS launching. I added an assertion to the existing pytest that this defaults to None, and added a new pytest that verifies a setting of true carries through to the task definition.

Hi @NickLavrov , thanks for this. I once explored implementing this for Dagster+ and I encountered pitfalls that I am not sure you'll also experience in a OSS context. There are, depending on logging setup or other configuration, files that may be written to the volume, not to mention what the actual user code does. To get the full value out of this change, you may have other hurdles to jump through, such as defining and mounting writable volumes to receive these files.

That being said, if that bit works correctly, then the rest can be incremental change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants