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

Add support to configure SecurityContext/allowPrivilegeEscalation for the deployed containers #512

Closed
gowrishdc opened this issue Dec 6, 2022 · 2 comments
Assignees
Milestone

Comments

@gowrishdc
Copy link

gowrishdc commented Dec 6, 2022

Description
Related Issue in spring cloud data flow project: issue created in dataflow project for the same

Note: I believe the code fix is probably in this project so adding /linking it here to get attention.

Require the Stream and Task PODS that are created by the deploy process have the capability to control controller level securityContext/allowPrivilegeEscalation attribute.

The resulting deployment creates the securityContext/allowPrivilegeEscalation for the container sections. However, it does not create the securityContext for the initContainers that are created for the "log" sink application which has a deployment count of 3. As part of that the App is "scaled" deployed with initContainer that does not have the securityContext.

The security policy stops all deployment that does not have securityContext/allowPrivilegeEscalation: false and that is causing this stream deployment to fail with this error message:

Error Message: [psp-allow-privilege-escalation-container] OPA-GATEKEEPER CONSTRAINT: Container index-provider is attempting to run without a required securityContext/allowPrivilegeEscalation, Allowed = false.]

Steps to reproduce:

> stream create --name "words" --definition "http --server.port=9001 | splitter --expression=payload.split(' ') | log"
> stream deploy --name "words" --propertiesFile words-stream.properties
> cat words-stream.properties
app.http.server.port=9001
app.splitter.expression=payload.split(' ')
app.splitter.producer.partitionKeyExpression=payload
deployer.log.count=3

deployer.http.kubernetes.deployment-labels=applicationid:123456
deployer.log.kubernetes.deployment-labels=applicationid:123456
deployer.splitter.kubernetes.deployment-labels=applicationid:123456

deployer.http.kubernetes.containerSecurityContext={allowPrivilegeEscalation: false}
deployer.log.kubernetes.containerSecurityContext={allowPrivilegeEscalation: false}
deployer.splitter.kubernetes.containerSecurityContext={allowPrivilegeEscalation: false}

Please let me know if you need more information.

Additional information:

podSpec.getInitContainers().add(createStatefulSetInitContainer(statefulSetInitContainerImageName));

private Container createStatefulSetInitContainer(String imageName) {
List<String> command = new LinkedList<>();
String commandString = String
.format("%s && %s", setIndexProperty("INSTANCE_INDEX"), setIndexProperty("spring.application.index"));
command.add("sh");
command.add("-c");
command.add(commandString);
return new ContainerBuilder().withName("index-provider")
.withImage(imageName)
.withImagePullPolicy("IfNotPresent")
.withCommand(command)
.withVolumeMounts(new VolumeMountBuilder().withName("config").withMountPath("/config").build())
.build();
}

Should the initContainer need something like this that is done for the container section:

SecurityContext containerSecurityContext = this.deploymentPropertiesResolver.getContainerSecurityContext(deploymentProperties);
if (containerSecurityContext != null) {
container.setSecurityContext(containerSecurityContext);
}

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Dec 6, 2022
@corneil corneil changed the title Add support to configure SecurityContext/allowPrivilegeEscalation for the deployed Streams and Tasks Add support to configure SecurityContext/allowPrivilegeEscalation for the deployed containers Dec 7, 2022
@corneil corneil added this to the General Backlog milestone Dec 7, 2022
@corneil
Copy link
Contributor

corneil commented Dec 7, 2022

We will need to add ContainerSecurityContext to InitContainer and ensure that the creation of the init container uses the properties.
We will prioritize this for SCDF 2.10.1 which is planned for early in the new year.

@corneil corneil self-assigned this Jan 17, 2023
@onobc onobc assigned onobc and unassigned corneil Jan 30, 2023
@onobc onobc removed the status/need-triage Team needs to triage and take a first look label Jan 30, 2023
@onobc onobc modified the milestones: General Backlog, 2.8.1 Jan 30, 2023
onobc added a commit to onobc/spring-cloud-deployer-kubernetes that referenced this issue Feb 7, 2023
* Add context to additional containers
* Add all available config props on security contexts

Co-authored-by: asinrus <arkadii_osheev@mail.ru>

See spring-cloud/spring-cloud-dataflow#5184
See spring-cloud#512
corneil pushed a commit that referenced this issue Feb 9, 2023
* Add security context to init containers

* Add context to additional containers
* Add all available config props on security contexts

Co-authored-by: asinrus <arkadii_osheev@mail.ru>

See spring-cloud/spring-cloud-dataflow#5184
See #512

* Renamed nested class to end w/ "IT" to avoid unit testing
@onobc
Copy link
Contributor

onobc commented Feb 9, 2023

Closed via de4ed59

@onobc onobc closed this as completed Feb 9, 2023
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

No branches or pull requests

3 participants