step ca sign rejects CSRs for GitLab CI OIDC tokens: the token is classified as a JWK token because of its sha claim

Aberta
#1,744 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
65/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
go

Direção de pesquisa

Start with token/parse.go and command/ca/sign.go, the two files named in the issue, and trace how Payload.Type() classifies tokens and how signing applies the CN check. Reproduce with a GitLab CI OIDC token containing a sha claim and a CSR whose common name differs from the token subject. Done when the CLI accepts the CSR for server-side validation while preserving the intended check for step-issued JWK tokens.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Version: step CLI, current master (token/parse.go, command/ca/sign.go). I didn't reproduce this on a release build, but I saw the same error in CI.

What happens

Signing a CSR with an ID token minted by GitLab CI (id_tokens:) fails when the CSR's common name differs from the token's sub:

token subject 'project_path:group/project:ref_protected:true' and CSR CommonName 'my-service' do not match

The CA is an OIDC provisioner, and the CA itself doesn't enforce this. Its OIDC AuthorizeSign attaches no CN-vs-token comparison, and the certificate template sets the subject. The error comes from command/ca/sign.go, which skips the CN check only when jwt.Payload.Type() is OIDC, AWS, GCP, Azure or K8sSA. It does so because, in its words, the CN "will be validated on the server side, it depends on server configuration."

Why

Payload.Type() in token/parse.go checks for JWK before OIDC:

case p.SHA != "" || len(p.SANs) > 0:
return JWK
case len(p.Audience) > 0 && p.Issuer != "" && p.Subject != "" && ...:
return OIDC

GitLab CI ID tokens always include a sha claim, the commit SHA (GitLab docs). In step's own JWK tokens, sha is the CSR fingerprint. A GitLab token is therefore classified as JWK and gets the JWK CN check, even though it is an OIDC token from another issuer.

Expected

A token from an OIDC issuer is treated as OIDC and step ca sign leaves the CN validation to the server.

Actual

The CLI rejects the CSR before sending it. Calling POST /1.0/sign directly with the same token and CSR, with a different CN, is accepted by the CA.

Repro

  1. Configure an OIDC provisioner trusting https://gitlab.example.com and a GitLab job with id_tokens: { TOKEN: { aud: } }.
  2. Create a CSR with step certificate create my-service svc.csr svc.key --csr.
  3. Run step ca sign svc.csr svc.crt --token "$TOKEN" in the job.
  4. You get the error above.

Possible fixes

  • Don't treat sha as a JWK marker on its own. For example, also require the issuer or the step-cli conventions that step-issued tokens have.
  • Or, in sign.go, skip the client-side CN comparison unless the token is a step-issued JWK token.

Happy to send a PR if you want one of these.

Linguagem predominante
Go
Estrelas
4.3k
Forks
320
Merge médio
1d 21h
PRs com merge (30d)
10

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de smallstep/cli

Todas as issues de smallstep/cli

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.