Skip to content

Unable to clone git repository as template if the repo is protected #3415

@M3nace

Description

@M3nace

I'm trying to use the --repository option of the kn CLI to create a function from a template hosted on a GitLab instance, but I get an error about authentication.

Non-working command:
kn func create myfunc -l python -t fastapi --repository "https://<my-gitlab-host>/kn-templates"

The error:

Error: failed to get repository from URI ("https://<my-gitlab-host>/kn-templates"): failed to clone repository: authentication required: HTTP Basic: Access denied. If a password was provided for Git authentication, the password was incorrect or you're required to use a token instead of a password. If a token was provided, it was either incorrect, expired, or improperly scoped. See https://<my-gitlab-host>/help/topics/git/troubleshooting_git.md#error-on-git-fetch-http-basic-access-denied

The repository visibility settings is set to internal (cue the authentication).

However, I've set up my .gitconfig to use a .git-credentials file in my /home, allowing me to clone the repository without providing any user/password.

$ cat ~/.gitconfig
[credential]
	helper = store
...

$ cat ~/.git-credentials 
https://<user>:<password>@<my-gitlab-host>
...

Working git clone command:
git clone https://<my-gitlab-host>/kn-templates

If I set the user/password in the URL, kn can clone and create the function.

Working command:
kn func create myfunc -l python -t fastapi --repository "https://<user>:<password>@<my-gitlab-host>/kn-templates"

Is there a way to configure kn to use the .gitconfig/.git-credentials of the user ?

nb: my kn binary comes from the OpenShift instance running locally, referenced in the webpage /command-line-tools. The cluster has the operator Red Hat OpenShift Serverless in version 1.37.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions