Ax
11/09/2023, 1:12 PMMarvin
11/09/2023, 1:12 PMdeploy key
for this. Deploy keys are SSH keys that are stored on your server and grant access to a single GitHub repository. This key is attached directly to the repository instead of to a personal user account.
Here are the steps to do it:
1. Generate a new SSH key on your server: ssh-keygen -t rsa -b 4096 -C "<mailto:your_email@example.com|your_email@example.com>"
2. Go to your GitHub repository settings.
3. Click on Deploy keys
and then on Add deploy key
.
4. Enter a title, paste the public key you generated on your server, and click Add key
.
Now, you can use SSH instead of HTTPS for your repository. For example, instead of <https://github.com/username/repo.git>
, you would use git@github.com:username/repo.git
.
Remember, the deploy key should be private and stay on your server. The public key is what you provide to GitHub.Ax
11/09/2023, 1:13 PMMarvin
11/09/2023, 1:13 PM<git+ssh://git@github.com/username/repo.git#egg=projectname>
However, as you mentioned, you don't want to reveal the token. Unfortunately, pip doesn't support SSH keys directly. You would need to have the SSH keys set up in your environment to use this method, which might not be suitable for your use case.
As an alternative, you can consider using a private PyPI server, or using a service like GitHub Packages or GitLab's package repositories to host your Python packages. These services provide methods to authenticate with tokens without revealing them in your package requirements.Ax
11/09/2023, 1:13 PMMarvin
11/09/2023, 1:14 PMGIT_SSH_COMMAND
environment variable to use the key:
bash
ssh-add /path/to/private/key
GIT_SSH_COMMAND="ssh -i /path/to/private/key"
4. Install the Package: Now you should be able to install the package using pip:
bash
pip install <git+ssh://git@github.com/username/repo.git#egg=projectname>
Remember to replace /path/to/private/key
with the actual path where you store the private key, and username/repo.git#egg=projectname
with your actual repository and package name.
This approach ensures that the private key is never exposed in your task definition or Dockerfile. It's fetched securely at runtime and used only for the duration of the task.