Skip to content

Commit ae960eb

Browse files
authored
feat!: support mTLS with gatekeeper and cert rotation (#2242)
Signed-off-by: Binbin Li <[email protected]>
1 parent d4603e0 commit ae960eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1088
-2039
lines changed

.github/licenserc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ header:
2929
limitations under the License.
3030
3131
paths-ignore:
32-
- "**/*.{md,svg,yaml,crt,cer,json,pub,yml,pb.go,proto,gotmpl}"
32+
- "**/*.{md,svg,yaml,crt,cer,json,pub,yml,pb.go,proto,gotmpl,tpl}"
3333
- "CODEOWNERS"
3434
- "PROJECT"
3535
- "NOTICE"

.github/workflows/codeql.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,5 @@ jobs:
4242
uses: github/codeql-action/init@60168efe1c415ce0f5521ea06d5c2062adbeed1b # tag=v3.28.17
4343
with:
4444
languages: go
45-
- name: Run tidy
46-
run: go mod tidy
47-
- name: Build CLI
48-
run: make build
4945
- name: Perform CodeQL Analysis
5046
uses: github/codeql-action/analyze@60168efe1c415ce0f5521ea06d5c2062adbeed1b # tag=v3.28.17

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14-
FROM golang:1.24-alpine@sha256:7772cb5322baa875edd74705556d08f0eeca7b9c4b5367754ce3f2f00041ccee AS builder
14+
FROM golang:1.24-alpine@sha256:ef18ee7117463ac1055f5a370ed18b8750f01589f13ea0b48642f5792b234044 AS builder
1515

1616
WORKDIR /app
1717

cmd/ratify-gatekeeper-provider/main.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/ratify-project/ratify/v2/internal/httpserver"
24+
"github.com/ratify-project/ratify/v2/internal/manager"
2425
"github.com/sirupsen/logrus"
2526
)
2627

@@ -33,11 +34,13 @@ func main() {
3334
}
3435

3536
type options struct {
36-
configFilePath string
37-
httpServerAddress string
38-
certFile string
39-
keyFile string
40-
verifyTimeout time.Duration
37+
configFilePath string
38+
httpServerAddress string
39+
certFile string
40+
keyFile string
41+
gatekeeperCACertFile string
42+
disableCertRotation bool
43+
verifyTimeout time.Duration
4144
}
4245

4346
func parse() *options {
@@ -46,7 +49,9 @@ func parse() *options {
4649
flag.StringVar(&opts.httpServerAddress, "address", "", "HTTP server address")
4750
flag.StringVar(&opts.certFile, "cert-file", "", "Path to the TLS certificate file")
4851
flag.StringVar(&opts.keyFile, "key-file", "", "Path to the TLS key file")
52+
flag.StringVar(&opts.gatekeeperCACertFile, "gatekeeper-ca-cert-file", "", "Path to the Gatekeeper CA certificate file")
4953
flag.DurationVar(&opts.verifyTimeout, "verify-timeout", 5*time.Second, "Verification timeout duration (e.g. 5s, 1m), default is 5 seconds")
54+
flag.BoolVar(&opts.disableCertRotation, "disable-cert-rotation", false, "Disable certificate rotation")
5055

5156
flag.Parse()
5257
logrus.Infof("Starting Ratify with options: %+v", opts)
@@ -57,11 +62,19 @@ func startRatify(opts *options) error {
5762
if len(opts.httpServerAddress) == 0 {
5863
return errors.New("HTTP server address is required")
5964
}
65+
var certRotatorReady chan struct{}
66+
if !opts.disableCertRotation {
67+
certRotatorReady = make(chan struct{})
68+
}
6069
serverOpts := &httpserver.ServerOptions{
61-
HTTPServerAddress: opts.httpServerAddress,
62-
CertFile: opts.certFile,
63-
KeyFile: opts.keyFile,
64-
VerifyTimeout: opts.verifyTimeout,
70+
HTTPServerAddress: opts.httpServerAddress,
71+
CertFile: opts.certFile,
72+
KeyFile: opts.keyFile,
73+
GatekeeperCACertFile: opts.gatekeeperCACertFile,
74+
VerifyTimeout: opts.verifyTimeout,
75+
CertRotatorReady: certRotatorReady,
6576
}
77+
78+
go manager.StartManager(certRotatorReady)
6679
return httpserver.StartServer(serverOpts, opts.configFilePath)
6780
}

cmd/ratify-gatekeeper-provider/main_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,19 @@ func TestStartRatify(t *testing.T) {
112112
{
113113
name: "missing http server address",
114114
opts: &options{
115-
configFilePath: "config.yaml",
116-
verifyTimeout: 5 * time.Second,
115+
configFilePath: "config.yaml",
116+
verifyTimeout: 5 * time.Second,
117+
disableCertRotation: true,
117118
},
118119
expectError: true,
119120
},
120121
{
121122
name: "failed to start the server",
122123
opts: &options{
123-
httpServerAddress: ":8080",
124-
configFilePath: "config.yaml",
125-
certFile: "cert.pem",
124+
httpServerAddress: ":8080",
125+
configFilePath: "config.yaml",
126+
certFile: "cert.pem",
127+
disableCertRotation: true,
126128
},
127129
expectError: true,
128130
},

cmd/ratify/cmd/discover.go

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)