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

Secrets-encryption rotation #4372

Merged
merged 71 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
f8085b6
Initial encrypt files
dereknola Oct 8, 2021
ddfb505
Regular CLI framework for encrypt commands
dereknola Oct 8, 2021
dddddea
Fix internalCLIAction
dereknola Oct 8, 2021
becae1c
Build k3s-encrypt binary
dereknola Oct 8, 2021
2bb7fd6
Add encrypt to server binary
dereknola Oct 11, 2021
07c5c4e
Initial status command complete
dereknola Oct 12, 2021
0c603f0
Initial Prepare command
dereknola Oct 12, 2021
f6fb0da
Added status subcommand
dereknola Oct 12, 2021
1967a0b
Swapped hashing to rotate prevention
dereknola Oct 12, 2021
81dbc18
Change package to secretsencrypt
dereknola Oct 13, 2021
333fe07
Merge branch 'k3s-io:master' into encryption_app
dereknola Oct 14, 2021
dc4c190
Implemented reencryption
dereknola Oct 15, 2021
ba10167
Add encryption toggle to main command
dereknola Oct 15, 2021
28233e4
Convert to server-side includes, implement state checks
dereknola Oct 18, 2021
6c3fd2b
Remove Hash annotation checks
dereknola Oct 18, 2021
3762d85
Converted prepare and status to server-side commands
dereknola Oct 19, 2021
bbadf13
Merge branch 'k3s-io:master' into encryption_app
dereknola Oct 19, 2021
19a9155
Converted reencrypt to server-side call
dereknola Oct 19, 2021
7809022
Add encryption enable/disable, Cleanup CLI
dereknola Oct 19, 2021
eb9f3b2
Cleanup main command
dereknola Oct 19, 2021
dac53da
Added hash encryption verification
dereknola Oct 19, 2021
775f5be
Added back encryption hash annotations
dereknola Oct 20, 2021
d32582b
Initial integration test
dereknola Oct 21, 2021
7ec3a63
Merge branch 'k3s-io:master' into encryption_app
dereknola Oct 26, 2021
a711faf
Merge branch 'encryption_app' of https://github.com/dereknola/k3s int…
dereknola Oct 26, 2021
e52cd99
Merge remote-tracking branch 'upstream/master' into encryption_app
dereknola Oct 29, 2021
eb979ae
Finished integration test
dereknola Oct 29, 2021
743ff56
Added encryption disable to test
dereknola Oct 29, 2021
5935edb
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 1, 2021
e209767
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 2, 2021
ccb7323
Review fixes, downsized number of http PUT endpoints
dereknola Nov 2, 2021
83c29c9
Merge branch 'encryption_app' of https://github.com/dereknola/k3s int…
dereknola Nov 2, 2021
94c57b0
Refactored redundant CLI flags
dereknola Nov 2, 2021
866735f
Converted main command to help output
dereknola Nov 2, 2021
b9710ad
Reduced boilerplate copy
dereknola Nov 3, 2021
b4148ca
Changed to enable instead of toggle
dereknola Nov 3, 2021
f8db860
Design call feedback, reworked status output
dereknola Nov 4, 2021
8ff076d
Updated integration test with new status
dereknola Nov 4, 2021
7c644f3
Convert status to return a struct, do string formatting on the client
dereknola Nov 5, 2021
2a58185
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 8, 2021
5ad9b06
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 9, 2021
6402a9c
Merge node label and annotation function
dereknola Nov 9, 2021
133dd4a
Combine enable and stage handler into config handler
dereknola Nov 9, 2021
fb4895d
Merge branch 'encryption_app' of https://github.com/dereknola/k3s int…
dereknola Nov 9, 2021
977913f
Merge with master
dereknola Nov 12, 2021
94484b0
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 12, 2021
b62e2bc
Initial fix for bootstrap save
dereknola Nov 15, 2021
5e227e2
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 15, 2021
ff3e29e
Further fixes, tested with external MySQL
dereknola Nov 16, 2021
50ad30f
Added skip flag
dereknola Nov 16, 2021
9aeb30e
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 16, 2021
28e94d6
Fixed skip functionality, secured errors
dereknola Nov 16, 2021
8d84623
Merge branch 'encryption_app' of https://github.com/dereknola/k3s int…
dereknola Nov 16, 2021
269968b
Added to integration test
dereknola Nov 16, 2021
d7683b2
golint-ci changes
dereknola Nov 18, 2021
7e805f4
Merge branch 'k3s-io:master' into encryption_app
dereknola Nov 29, 2021
3e41240
CI Testing fixes
dereknola Nov 29, 2021
52fae9b
Nit fixes from review
dereknola Nov 30, 2021
757b464
Exit if fail to reencrypt all secrets
dereknola Nov 30, 2021
0c1ba7a
Reworked encrytion state file and combined with annotation
dereknola Dec 3, 2021
6ef8f2b
Initial controller rework
dereknola Dec 3, 2021
a9843a4
Update node before applying annontation
dereknola Dec 3, 2021
d137c80
Finished controller, update int test
dereknola Dec 6, 2021
f3eeb6c
Merge branch 'master' into encryption_app
dereknola Dec 6, 2021
6085de3
Fix bootstrap on embedded etcd
dereknola Dec 7, 2021
f0b8a57
golang-lintci fix
dereknola Dec 7, 2021
e239ee5
codespell
dereknola Dec 7, 2021
e432c1a
Fix to bootstrap on restart of joing nodes
dereknola Dec 7, 2021
b446de9
Consolidate event recorder
dereknola Dec 7, 2021
b4ed675
Include nodeName in events
dereknola Dec 7, 2021
d83ae1b
Consolidate node name
dereknola Dec 7, 2021
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
13 changes: 2 additions & 11 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,8 @@ jobs:
- name: Run Integration Tests
run: |
chmod +x ./dist/artifacts/k3s
go test -coverpkg=./... -coverprofile=coverage.out ./pkg/... -run Integration
go tool cover -func coverage.out
# these tests do not relate to coverage and must be run separately
go test ./tests/integration/... -run Integration
go test ./pkg/... ./tests/integration/... -run Integration
- name: On Failure, Launch Debug Session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 5
- name: Upload Results To Codecov
uses: codecov/codecov-action@v1
with:
files: ./coverage.out
flags: inttests # optional
verbose: true # optional (default = false)
timeout-minutes: 5
32 changes: 32 additions & 0 deletions cmd/encrypt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"context"
"errors"
"os"

"github.com/rancher/k3s/pkg/cli/cmds"
"github.com/rancher/k3s/pkg/cli/secretsencrypt"
"github.com/rancher/k3s/pkg/configfilearg"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)

func main() {
app := cmds.NewApp()
app.Commands = []cli.Command{
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp,
cmds.NewSecretsEncryptSubcommands(
secretsencrypt.Status,
secretsencrypt.Enable,
secretsencrypt.Disable,
secretsencrypt.Prepare,
secretsencrypt.Rotate,
secretsencrypt.Reencrypt),
),
}

if err := app.Run(configfilearg.MustParse(os.Args)); err != nil && !errors.Is(err, context.Canceled) {
logrus.Fatal(err)
}
}
10 changes: 10 additions & 0 deletions cmd/k3s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
}

etcdsnapshotCommand := internalCLIAction(version.Program+"-"+cmds.EtcdSnapshotCommand, dataDir, os.Args)
secretsencryptCommand := internalCLIAction(version.Program+"-"+cmds.SecretsEncryptCommand, dataDir, os.Args)
certCommand := internalCLIAction(version.Program+"-"+cmds.CertCommand, dataDir, os.Args)

// Handle subcommand invocation (k3s server, k3s crictl, etc)
Expand All @@ -53,6 +54,15 @@ func main() {
etcdsnapshotCommand,
etcdsnapshotCommand),
),
cmds.NewSecretsEncryptCommand(secretsencryptCommand,
cmds.NewSecretsEncryptSubcommands(
secretsencryptCommand,
secretsencryptCommand,
secretsencryptCommand,
secretsencryptCommand,
secretsencryptCommand,
secretsencryptCommand),
),
cmds.NewCertCommand(
cmds.NewCertSubcommands(
certCommand),
Expand Down
10 changes: 10 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/rancher/k3s/pkg/cli/ctr"
"github.com/rancher/k3s/pkg/cli/etcdsnapshot"
"github.com/rancher/k3s/pkg/cli/kubectl"
"github.com/rancher/k3s/pkg/cli/secretsencrypt"
"github.com/rancher/k3s/pkg/cli/server"
"github.com/rancher/k3s/pkg/configfilearg"
"github.com/rancher/k3s/pkg/containerd"
Expand Down Expand Up @@ -53,6 +54,15 @@ func main() {
etcdsnapshot.Prune,
etcdsnapshot.Run),
),
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp,
cmds.NewSecretsEncryptSubcommands(
secretsencrypt.Status,
secretsencrypt.Enable,
secretsencrypt.Disable,
secretsencrypt.Prepare,
secretsencrypt.Rotate,
secretsencrypt.Reencrypt),
),
cmds.NewCertCommand(
cmds.NewCertSubcommands(
cert.Run),
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/rancher/k3s/pkg/cli/crictl"
"github.com/rancher/k3s/pkg/cli/etcdsnapshot"
"github.com/rancher/k3s/pkg/cli/kubectl"
"github.com/rancher/k3s/pkg/cli/secretsencrypt"
"github.com/rancher/k3s/pkg/cli/server"
"github.com/rancher/k3s/pkg/configfilearg"
"github.com/sirupsen/logrus"
Expand All @@ -37,6 +38,15 @@ func main() {
etcdsnapshot.Prune,
etcdsnapshot.Run),
),
cmds.NewSecretsEncryptCommand(cli.ShowAppHelp,
cmds.NewSecretsEncryptSubcommands(
secretsencrypt.Status,
secretsencrypt.Enable,
secretsencrypt.Disable,
secretsencrypt.Prepare,
secretsencrypt.Rotate,
secretsencrypt.Reencrypt),
),
cmds.NewCertCommand(
cmds.NewCertSubcommands(
cert.Run),
Expand Down
19 changes: 10 additions & 9 deletions pkg/cli/cmds/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ type AgentShared struct {
}

var (
appName = filepath.Base(os.Args[0])
AgentConfig Agent
NodeIPFlag = cli.StringSliceFlag{
appName = filepath.Base(os.Args[0])
AgentConfig Agent
AgentTokenFlag = cli.StringFlag{
Name: "token,t",
Usage: "(cluster) Token to use for authentication",
EnvVar: version.ProgramUpper + "_TOKEN",
Destination: &AgentConfig.Token,
}
NodeIPFlag = cli.StringSliceFlag{
Name: "node-ip,i",
Usage: "(agent/networking) IPv4/IPv6 addresses to advertise for node",
Value: &AgentConfig.NodeIP,
Expand Down Expand Up @@ -217,12 +223,7 @@ func NewAgentCommand(action func(ctx *cli.Context) error) cli.Command {
VModule,
LogFile,
AlsoLogToStderr,
cli.StringFlag{
Name: "token,t",
Usage: "(cluster) Token to use for authentication",
EnvVar: version.ProgramUpper + "_TOKEN",
Destination: &AgentConfig.Token,
},
AgentTokenFlag,
cli.StringFlag{
Name: "token-file",
Usage: "(cluster) Token file to use for authentication",
Expand Down
6 changes: 1 addition & 5 deletions pkg/cli/cmds/etcd_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ var EtcdSnapshotFlags = []cli.Flag{
EnvVar: version.ProgramUpper + "_NODE_NAME",
Destination: &AgentConfig.NodeName,
},
cli.StringFlag{
Name: "data-dir,d",
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
Destination: &ServerConfig.DataDir,
},
DataDirFlag,
&cli.StringFlag{
Name: "dir,etcd-snapshot-dir",
Usage: "(db) Directory to save etcd on-demand snapshot. (default: ${data-dir}/db/snapshots)",
Expand Down
94 changes: 94 additions & 0 deletions pkg/cli/cmds/secrets_encrypt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package cmds

import (
"github.com/urfave/cli"
)

const SecretsEncryptCommand = "secrets-encrypt"

var EncryptFlags = []cli.Flag{
DataDirFlag,
ServerToken,
}

func NewSecretsEncryptCommand(action func(*cli.Context) error, subcommands []cli.Command) cli.Command {
return cli.Command{
Name: SecretsEncryptCommand,
Usage: "Control secrets encryption and keys rotation",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: action,
Subcommands: subcommands,
}
}

func NewSecretsEncryptSubcommands(status, enable, disable, prepare, rotate, reencrypt func(ctx *cli.Context) error) []cli.Command {
return []cli.Command{
{
Name: "status",
Usage: "Print current status of secrets encryption",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: status,
Flags: EncryptFlags,
},
{
Name: "enable",
Usage: "Enable secrets encryption",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: enable,
Flags: EncryptFlags,
},
{
Name: "disable",
Usage: "Disable secrets encryption",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: disable,
Flags: EncryptFlags,
},
{
Name: "prepare",
Usage: "Prepare for encryption keys rotation",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: prepare,
Flags: append(EncryptFlags, &cli.BoolFlag{
Name: "f,force",
Usage: "Force preparation.",
Destination: &ServerConfig.EncryptForce,
}),
},
{
Name: "rotate",
Usage: "Rotate secrets encryption keys",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: rotate,
Flags: append(EncryptFlags, &cli.BoolFlag{
Name: "f,force",
Usage: "Force key rotation.",
Destination: &ServerConfig.EncryptForce,
}),
},
{
Name: "reencrypt",
Usage: "Reencrypt all data with new encryption key",
SkipFlagParsing: false,
SkipArgReorder: true,
Action: reencrypt,
Flags: append(EncryptFlags,
&cli.BoolFlag{
Name: "f,force",
Usage: "Force secrets reencryption.",
Destination: &ServerConfig.EncryptForce,
},
&cli.BoolFlag{
Name: "skip",
Usage: "Skip removing old key",
Destination: &ServerConfig.EncryptSkip,
}),
},
}
}
28 changes: 16 additions & 12 deletions pkg/cli/cmds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ type Server struct {
ClusterReset bool
ClusterResetRestorePath string
EncryptSecrets bool
EncryptForce bool
EncryptSkip bool
SystemDefaultRegistry string
StartupHooks []StartupHook
EtcdSnapshotName string
Expand All @@ -97,7 +99,18 @@ type Server struct {

var (
ServerConfig Server
ClusterCIDR = cli.StringSliceFlag{
DataDirFlag = cli.StringFlag{
Name: "data-dir,d",
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
Destination: &ServerConfig.DataDir,
}
ServerToken = cli.StringFlag{
Name: "token,t",
Usage: "(cluster) Shared secret used to join a server or agent to a cluster",
Destination: &ServerConfig.Token,
EnvVar: version.ProgramUpper + "_TOKEN",
}
ClusterCIDR = cli.StringSliceFlag{
Name: "cluster-cidr",
Usage: "(networking) IPv4/IPv6 network CIDRs to use for pod IPs (default: 10.42.0.0/16)",
Value: &ServerConfig.ClusterCIDR,
Expand Down Expand Up @@ -179,11 +192,7 @@ var ServerFlags = []cli.Flag{
Usage: "(listener) Add additional hostnames or IPv4/IPv6 addresses as Subject Alternative Names on the server TLS cert",
Value: &ServerConfig.TLSSan,
},
cli.StringFlag{
Name: "data-dir,d",
Usage: "(data) Folder to hold state default /var/lib/rancher/" + version.Program + " or ${HOME}/.rancher/" + version.Program + " if not root",
Destination: &ServerConfig.DataDir,
},
DataDirFlag,
ClusterCIDR,
ServiceCIDR,
ServiceNodePortRange,
Expand All @@ -195,12 +204,7 @@ var ServerFlags = []cli.Flag{
Destination: &ServerConfig.FlannelBackend,
Value: "vxlan",
},
cli.StringFlag{
Name: "token,t",
Usage: "(cluster) Shared secret used to join a server or agent to a cluster",
Destination: &ServerConfig.Token,
EnvVar: version.ProgramUpper + "_TOKEN",
},
ServerToken,
cli.StringFlag{
Name: "token-file",
Usage: "(cluster) File containing the cluster-secret/token",
Expand Down
Loading