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

added PodSecurityContext #2174

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion cmd/create.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd

Check failure on line 1 in cmd/create.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/cmd/create.go b/cmd/create.go index 4263c0c..b123135 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -568,4 +568,4 @@ func RuntimeTemplateOptions(client *fn.Client) (string, error) { } writer.Flush() return builder.String(), nil -} \ No newline at end of file +}

import (
"errors"
Expand Down Expand Up @@ -568,4 +568,4 @@
}
writer.Flush()
return builder.String(), nil
}
}

Check failure on line 571 in cmd/create.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[EOF Newline] reported by reviewdog 🐶 Missing newline Raw Output: cmd/create.go:571: Missing newline
4 changes: 3 additions & 1 deletion pkg/functions/function.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package functions

Check failure on line 1 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/functions/function.go b/pkg/functions/function.go index 459f8cc..dd9c587 100644 --- a/pkg/functions/function.go +++ b/pkg/functions/function.go @@ -141,7 +141,7 @@ type RunSpec struct { // Env variables to be set Envs Envs `yaml:"envs,omitempty"` - + // PodSecurityContext to be set for read and write permission PodSecurityContext PodSecurityContext `yaml:"podSecurityContext, omitempty"` // StartTimeout specifies that this function should have a custom timeout

import (
"errors"
Expand Down Expand Up @@ -141,7 +141,9 @@

// Env variables to be set
Envs Envs `yaml:"envs,omitempty"`


Check failure on line 144 in pkg/functions/function.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[trailing whitespace] reported by reviewdog 🐶 Raw Output: pkg/functions/function.go:144:
// PodSecurityContext to be set for read and write permission
PodSecurityContext PodSecurityContext `yaml:"podSecurityContext, omitempty"`
// StartTimeout specifies that this function should have a custom timeout
// when starting. This setting is currently respected by the host runner,
// with containerized docker runner and deployed Knative service integration
Expand Down
8 changes: 8 additions & 0 deletions pkg/functions/function_security.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package functions

Check failure on line 1 in pkg/functions/function_security.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/functions/function_security.go b/pkg/functions/function_security.go index 08bbc5e..e516b0a 100644 --- a/pkg/functions/function_security.go +++ b/pkg/functions/function_security.go @@ -1,8 +1,8 @@ package functions type PodSecurityContext struct { - RunAsUser *int64 `yaml:"RunAsUser,omitempty"` - RunAsGroup *int64 `yaml:"RunAsGroup,omitempty"` - RunAsNonRoot *bool `yaml:"RunAsNonRoot,omitempty"` - FSGroup *int64 `yaml:"FSGroup,omitempty"` + RunAsUser *int64 `yaml:"RunAsUser,omitempty"` + RunAsGroup *int64 `yaml:"RunAsGroup,omitempty"` + RunAsNonRoot *bool `yaml:"RunAsNonRoot,omitempty"` + FSGroup *int64 `yaml:"FSGroup,omitempty"` }

type PodSecurityContext struct {
RunAsUser *int64 `yaml:"RunAsUser,omitempty"`
RunAsGroup *int64 `yaml:"RunAsGroup,omitempty"`
RunAsNonRoot *bool `yaml:"RunAsNonRoot,omitempty"`
FSGroup *int64 `yaml:"FSGroup,omitempty"`
}
13 changes: 12 additions & 1 deletion pkg/knative/deployer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package knative

Check failure on line 1 in pkg/knative/deployer.go

View workflow job for this annotation

GitHub Actions / style / Golang / Auto-format and Check

Please run goimports. diff --git a/pkg/knative/deployer.go b/pkg/knative/deployer.go index 19e201e..84e8460 100644 --- a/pkg/knative/deployer.go +++ b/pkg/knative/deployer.go @@ -435,7 +435,7 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service, for k, v := range annotations { revisionAnnotations[k] = v } - PodSecurityContext := getPodSecurityContext(f.Run) + PodSecurityContext := getPodSecurityContext(f.Run) service := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: f.Name, @@ -1077,12 +1077,12 @@ func setServiceOptions(template *v1.RevisionTemplateSpec, options fn.Options) er return servingclientlib.UpdateRevisionTemplateAnnotations(template, toUpdate, toRemove) } -func getPodSecurityContext(RunSpec fn.RunSpec) *corev1.PodSecurityContext{ - return &corev1.PodSecurityContext{ - RunAsUser: RunSpec.PodSecurityContext.RunAsUser, - RunAsGroup: RunSpec.PodSecurityContext.RunAsGroup, +func getPodSecurityContext(RunSpec fn.RunSpec) *corev1.PodSecurityContext { + return &corev1.PodSecurityContext{ + RunAsUser: RunSpec.PodSecurityContext.RunAsUser, + RunAsGroup: RunSpec.PodSecurityContext.RunAsGroup, RunAsNonRoot: RunSpec.PodSecurityContext.RunAsNonRoot, - FSGroup: RunSpec.PodSecurityContext.FSGroup, + FSGroup: RunSpec.PodSecurityContext.FSGroup, } -} \ No newline at end of file +}

import (
"context"
Expand Down Expand Up @@ -435,7 +435,7 @@
for k, v := range annotations {
revisionAnnotations[k] = v
}

PodSecurityContext := getPodSecurityContext(f.Run)
service := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: f.Name,
Expand All @@ -451,6 +451,7 @@
},
Spec: v1.RevisionSpec{
PodSpec: corev1.PodSpec{
SecurityContext: PodSecurityContext,
Containers: []corev1.Container{
container,
},
Expand Down Expand Up @@ -1075,3 +1076,13 @@

return servingclientlib.UpdateRevisionTemplateAnnotations(template, toUpdate, toRemove)
}

func getPodSecurityContext(RunSpec fn.RunSpec) *corev1.PodSecurityContext{
return &corev1.PodSecurityContext{
RunAsUser: RunSpec.PodSecurityContext.RunAsUser,
RunAsGroup: RunSpec.PodSecurityContext.RunAsGroup,
RunAsNonRoot: RunSpec.PodSecurityContext.RunAsNonRoot,
FSGroup: RunSpec.PodSecurityContext.FSGroup,
}

}

Check failure on line 1088 in pkg/knative/deployer.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[EOF Newline] reported by reviewdog 🐶 Missing newline Raw Output: pkg/knative/deployer.go:1088: Missing newline
22 changes: 21 additions & 1 deletion schema/func_yaml-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"type": "object",
"description": "BuilderImages define optional explicit builder images to use by\nbuilder implementations in leau of the in-code defaults. They key\nis the builder's short name. For example:\nbuilderImages:\n pack: example.com/user/my-pack-node-builder\n s2i: example.com/user/my-s2i-node-builder"
"description// with containerized docker runner and deployed Knative service integration": "BuilderImages define optional explicit builder images to use by\nbuilder implementations in leau of the in-code defaults. They key\nis the builder's short name. For example:\nbuilderImages:\n pack: example.com/user/my-pack-node-builder\n s2i: example.com/user/my-s2i-node-builder"
Copy link
Member

Choose a reason for hiding this comment

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

This looks a bit odd?

},
"buildpacks": {
"items": {
Expand Down Expand Up @@ -352,6 +352,26 @@
"type": "array",
"description": "Env variables to be set"
},
"podSecurityContext": {
"properties": {
"RunAsUser": {
"pattern": "^[-._a-zA-Z][-._a-zA-Z0-9]*$",
"type": "integer"
},
"RunAsGroup": {
"type": "integer"
},
"RunAsNonRoot":{
"type": "boolean"
},
"FSGroup":{
"type":"integer"
}
},
"additionalProperties": false,
"type": "object"

Check failure on line 373 in schema/func_yaml-schema.json

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[trailing whitespace] reported by reviewdog 🐶 Raw Output: schema/func_yaml-schema.json:373:
},
"startTimeout": {
"type": "integer",
"description": "StartTimeout specifies that this function should have a custom timeout\nwhen starting. This setting is currently respected by the host runner,\nwith containerized docker runner and deployed Knative service integration\nin development."
Expand Down
Loading