Просмотр исходного кода

Add token and subject to K8sSA provisioner to be used in custom
templates.

Mariano Cano 6 лет назад
Родитель
Сommit
cf2989a848
1 измененных файлов с 8 добавлено и 2 удалено
  1. 8 2
      authority/provisioner/k8sSA.go

+ 8 - 2
authority/provisioner/k8sSA.go

@@ -206,13 +206,19 @@ func (p *K8sSA) AuthorizeRevoke(ctx context.Context, token string) error {
 
 // AuthorizeSign validates the given token.
 func (p *K8sSA) AuthorizeSign(ctx context.Context, token string) ([]SignOption, error) {
-	if _, err := p.authorizeToken(token, p.audiences.Sign); err != nil {
+	claims, err := p.authorizeToken(token, p.audiences.Sign)
+	if err != nil {
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "k8ssa.AuthorizeSign")
 	}
 
+	// Add some values to use in custom templates.
+	data := x509util.NewTemplateData()
+	data.SetToken(claims)
+	data.SetCommonName(claims.ServiceAccountName)
+
 	// Certificate templates: on K8sSA the default template is the certificate
 	// request.
-	templateOptions, err := CustomTemplateOptions(p.Options, x509util.NewTemplateData(), x509util.CertificateRequestTemplate)
+	templateOptions, err := CustomTemplateOptions(p.Options, data, x509util.CertificateRequestTemplate)
 	if err != nil {
 		return nil, errs.Wrap(http.StatusInternalServerError, err, "k8ssa.AuthorizeSign")
 	}