Skip to content

feat: add bearer token support for http sync.go#435

Open
husira wants to merge 1 commit intocarvel-dev:developfrom
husira:develop
Open

feat: add bearer token support for http sync.go#435
husira wants to merge 1 commit intocarvel-dev:developfrom
husira:develop

Conversation

@husira
Copy link

@husira husira commented Dec 26, 2025

This PR adds Bearer token authentication support to vendir sync (http) command:

In addition to existing HTTP Basic Auth (username / password), users can now authenticate using a Bearer token provided via secretRef.

Exactly one authentication method is allowed per secret:
• username + password → HTTP Basic Auth
• token → Authorization: Bearer

Mixed or incomplete credentials are rejected with clear validation errors.

We are using vendir to sync files from JFrog Artifactory. Our organization enforces authentication via access tokens instead of username/password. The authentication with JFrog Artifactory is implemented using Bearer tokens.

# use of username / password
apiVersion: v1
kind: Secret
metadata:
  name: secret-ref
data:
  username: dXNlcm5hbWU=
  password: cGFzc3dvcmQ=
---
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
  - path: <path>
    contents:
    - path: "."
      http:
        url: https://<url>
        secretRef:
          name: secret-ref
# use of token
apiVersion: v1
kind: Secret
metadata:
  name: secret-ref
data:
  token: dG9rZW4=
---
apiVersion: vendir.k14s.io/v1alpha1
kind: Config
directories:
  - path: <path>
    contents:
    - path: "."
      http:
        url: https://<url>
        secretRef:
          name: secret-ref

I could successfully test the implementation with our registry (JFrog Artifactory) using username/password or a Bearer token.

Signed-off-by: Raphael Husistein <raphael.husistein@hotmail.com>
@husira husira changed the title feat: add bearer token support for sync.go feat: add bearer token support for http sync.go Dec 26, 2025
Copy link
Member

@joaopapereira joaopapereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
Sorry for the very very late reply but this PR felt out of my radar :(
Thanks for creating this PR.

I have some comments that would like for you to address in order to move forward with this PR
Thanks

token, hasToken := secret.Data[ctlconf.SecretK8sCorev1HTTPBearerTokenKey]

// Be strict about basic auth fields: require username and password together.
if hasUser && !hasPass {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is not the greatest policy but can the password not be empty? In this case the password is not required. maybe this is a little bit too strict.

The next check I think is ok.

}

// Do not allow mixing basic auth and bearer token in the same secret.
if hasToken && (hasUser || hasPass) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if hasToken && (hasUser || hasPass) {
if hasToken && hasUser {

There should be no password field if the user is not present. Also we already do this validation in the livens above

@@ -0,0 +1,191 @@
package http
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package http
package http_test

ctlconf "carvel.dev/vendir/pkg/vendir/config"
)

/*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the tests please refer to other examples like https://github.com/carvel-dev/vendir/blob/develop/pkg/vendir/fetch/cache/cache_test.go where we use github.com/stretchr/testify/require do to assertions to keep the tests consistent through the project

@github-project-automation github-project-automation bot moved this to In Progress in Carvel Feb 3, 2026
@husira
Copy link
Author

husira commented Feb 16, 2026

Hey @joaopapereira

Thank you for the updates!

I am currently traveling until mid-April. Therefore, I am unable to continue working on it at this time.

@patrickmx, Do you find time to take a look at this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants