Skip to content

Commit

Permalink
split key default to false (#46)
Browse files Browse the repository at this point in the history
* draft

Signed-off-by: wfan <wfan@lycorp.co.jp>

* hash

Signed-off-by: wfan <wfan@lycorp.co.jp>

* log

Signed-off-by: wfan <wfan@lycorp.co.jp>

* Update cmd/athenz-sia/main.go

Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>

* Update pkg/identity/certificated.go

Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>

* Update pkg/identity/healthcheckd.go

Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>

* Update pkg/identity/metricsd.go

Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>

* Update pkg/token/daemon.go

Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>

---------

Signed-off-by: wfan <wfan@lycorp.co.jp>
Signed-off-by: Windz <WindzCUHK@users.noreply.github.com>
Co-authored-by: Aaron Jeongwoo Kim <53258958+mlajkim@users.noreply.github.com>
  • Loading branch information
WindzCUHK and mlajkim authored Oct 26, 2023
1 parent 6b5a231 commit dbbf93b
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
6 changes: 3 additions & 3 deletions athenz-sia.env
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ ROLECERT_DIR=
#
ROLE_CERT_FILENAME_DELIMITER=:role.
#
# Outputs private key specifically for role certificates (e.g. :true or false)
# Default value for binary: https://github.com/AthenZ/k8s-athenz-sia/blob/c8478297a9d228ffc0a6a1ea469ad0ef8a682dc8/pkg/config/default.go#L92
# Outputs private key specifically for role certificates (e.g. true or false)
# Default value for binary: https://github.com/AthenZ/k8s-athenz-sia/blob/7cedb649397adb59afdaaa821cfa0b1d226b7203/pkg/config/default.go#L92
#
ROLE_CERT_KEY_FILE_OUTPUT=true
ROLE_CERT_KEY_FILE_OUTPUT=false
#
# Athenz Role Auth Header to retrieve role tokens
# Default value for binary: https://github.com/AthenZ/k8s-athenz-sia/blob/c8478297a9d228ffc0a6a1ea469ad0ef8a682dc8/pkg/config/default.go#L41
Expand Down
4 changes: 2 additions & 2 deletions cmd/athenz-sia/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func main() {
}

if !idConfig.Init {
<-ch // wait until receiving os.Signal from channel ch
log.Println("Shutting down...")
s := <-ch // wait until receiving os.Signal from channel ch
log.Printf("Initiating shutdown with received signal %s ...\n", s.String())
}

close(certificateChan)
Expand Down
9 changes: 9 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ func (idConfig *IdentityConfig) validateAndInit() (err error) {
PollInterval: pollInterval,
})

// if certificate provisioning is disabled (use external key) and splitting role certificate key file is disabled, role certificate and external key mismatch problem may occur when external key rotates.
// error case: issue role certificate, rotate external key, mismatch period, issue role certificate, resolve, rotate external key, ...
if idConfig.ProviderService == "" && !idConfig.RoleCertKeyFileOutput {
// if role certificate issuing is enabled, warn user about the mismatch problem
if idConfig.TargetDomainRoles != "" && idConfig.RoleCertDir != "" {
log.Warnf("Rotating KEY_FILE[%s] may cause key mismatch with issued role certificate due to different rotation cycle. Please manually restart SIA when you rotate the key file.", idConfig.KeyFile)
}
}

// During the init flow if X.509 cert(and key) already exists,
// - someone is attempting to run init after a pod has been started
// - pod sandbox crashed and kubelet runs the init container
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func DefaultIdentityConfig() *IdentityConfig {
TargetDomainRoles: "",
RoleCertDir: "",
RoleCertFilenameDelimiter: DEFAULT_ROLE_CERT_FILENAME_DELIMITER,
RoleCertKeyFileOutput: true,
RoleCertKeyFileOutput: false,
RoleAuthHeader: DEFAULT_ROLE_AUTH_HEADER,
TokenType: "accesstoken",
TokenRefresh: DEFAULT_TOKEN_REFRESH,
Expand All @@ -114,7 +114,7 @@ func DefaultIdentityConfig() *IdentityConfig {
rawMode: "init",
rawRefresh: "24h",
rawDelayJitterSeconds: "0",
rawRoleCertKeyFileOutput: "true",
rawRoleCertKeyFileOutput: "false",
rawTokenRefresh: DEFAULT_TOKEN_REFRESH.String(),
rawTokenExpiry: DEFAULT_TOKEN_EXPIRY.String(),
rawTokenServerRESTAPI: "false",
Expand Down
5 changes: 2 additions & 3 deletions pkg/identity/certificated.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func Certificated(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (er
return errors.Wrap(err, "unable to save x509 role cert")
}

// always output role cert key file to prevent unexpected key rotation when using external key
if id == nil || idConfig.RoleCertKeyFileOutput {
if idConfig.RoleCertKeyFileOutput {
outKeyPath := filepath.Join(idConfig.RoleCertDir, rolecert.Domain+idConfig.RoleCertFilenameDelimiter+rolecert.Role+".key.pem")
log.Debugf("Saving x509 role cert key[%d bytes] at [%s]", len(roleKeyPEM), outKeyPath)
if err := w.AddBytes(outKeyPath, 0644, roleKeyPEM); err != nil {
Expand Down Expand Up @@ -354,7 +353,7 @@ func Certificated(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (er
log.Errorf("Failed to refresh x509 certificate after multiple retries: %s", err.Error())
}
case <-stopChan:
log.Info("Certificate provider will shutdown")
log.Info("Initiating shutdown of certificate provider daemon ...")
err = deleteRequest()
if err != nil {
log.Errorf("Failed to delete x509 certificate Instance ID record: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/identity/healthcheckd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func Healthcheckd(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (er
defer close(shutdownChan)

<-stopChan
log.Info("Health check server will shutdown")
log.Info("Initiating shutdown of health check daemon ...")
ctx, cancel := context.WithTimeout(context.Background(), idConfig.ShutdownTimeout)
defer cancel()
healthCheckServer.SetKeepAlivesEnabled(false)
Expand Down
2 changes: 1 addition & 1 deletion pkg/identity/metricsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Metricsd(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (error,
defer close(shutdownChan)

<-stopChan
log.Info("Metrics exporter will shutdown")
log.Info("Initiating shutdown of metrics exporter daemon ...")
// context.Background() is used, no timeout
err := exporter.Shutdown()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/token/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func Tokend(idConfig *config.IdentityConfig, stopChan <-chan struct{}) (error, <
log.Errorf("Failed to refresh tokens after multiple retries: %s", err.Error())
}
case <-stopChan:
log.Info("Token provider will shutdown")
log.Info("Initiating shutdown of token provider daemon ...")
time.Sleep(idConfig.ShutdownDelay)
ctx, cancel := context.WithTimeout(context.Background(), idConfig.ShutdownTimeout)
defer cancel()
Expand Down

0 comments on commit dbbf93b

Please sign in to comment.