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

feat/cli: allow to extract the default seccomp profile #8800

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/concourse/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type ConcourseCommand struct {
RetireWorker retire.RetireWorkerCommand `command:"retire-worker" description:"Safely remove a worker from the cluster permanently."`

GenerateKey GenerateKeyCommand `command:"generate-key" description:"Generate RSA key for use with Concourse components."`

ExtractInternalConfig ExtractInternalConfigCommand `command:"dump-internal-config" description:"Extract internal built in configuration as files that can be modified."`
}

func (cmd ConcourseCommand) LessenRequirements(parser *flags.Parser) {
Expand Down
28 changes: 28 additions & 0 deletions cmd/concourse/generate_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"os"

bespec "github.com/concourse/concourse/worker/runtime/spec"

"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -74,3 +78,27 @@ func (cmd *GenerateKeyCommand) Execute(args []string) error {

return nil
}

type ExtractInternalConfigCommand struct {
Copy link
Member

Choose a reason for hiding this comment

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

Feels weird having this sub-command in this file. Would make more sense to have it in its own file. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

FilePath string `short:"f" long:"filename" required:"true" description:"File path where the key shall be created. When generating ssh keys, the public key will be stored in a file with the same name but with '.pub' appended."`
Copy link
Member

Choose a reason for hiding this comment

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

The description here appears to not be updated. It talks about ssh keys but it looks like it's actually the destination you want the seccomp profile written to.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe change the longname to something else to, like output-file.


Seccomp bool `long:"seccomp" required:"false" description:"Extract the default builtin seccomp filter"`
}

func (cmd *ExtractInternalConfigCommand) Execute(args []string) error {
var dest = cmd.FilePath
if cmd.Seccomp {
seccompfilter := bespec.GetDefaultSeccompProfile()
Copy link
Member

Choose a reason for hiding this comment

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

So the whole point of this command is to print the seccomp variable from https://github.com/concourse/concourse/blob/master/worker/runtime/spec/seccomp.go in json format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because that's what then could be modified and re-used as baseline for custom trim down or extension based on use case and re-supplied to the containerd runner

bytes, err := json.Marshal(seccompfilter)
if err != nil {
return fmt.Errorf("failed to serialize key file: %s", err)
}
err = ioutil.WriteFile(dest, bytes, 0644)
if err != nil {
return fmt.Errorf("failed to write json to file: %s @ %s", err, dest)
}
return nil
} else {
return fmt.Errorf("Nothing to extract, use one of the optional flags for the subcommand")
}
}