Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept GITHUB_TOKEN for authentication #16

Open
bradrydzewski opened this issue May 8, 2018 · 11 comments
Open

Accept GITHUB_TOKEN for authentication #16

bradrydzewski opened this issue May 8, 2018 · 11 comments
Labels
enhancement New feature or request

Comments

@bradrydzewski
Copy link
Member

I just wanted to document an idea for a feature. We could add a GITHUB_TOKEN secret which will automatically use the token as the username, and set the password to x-oauth-basic.

This is possible today, however, I get the sense that most people don't realize it is an option. Providing some nice syntactic sugar to the existing username and password parameters could make this capability more accessible, since I think a token is always preferable to a username and password.

@bradrydzewski bradrydzewski added the enhancement New feature or request label May 8, 2018
@tboerger
Copy link
Contributor

tboerger commented May 8, 2018

A username with a token also works totally fine, that's how I'm using it because of 2fa.

@donny-dont
Copy link
Contributor

@bradrydzewski one thought I've had, and you know of this but I'll write it out here, is that if we treat the drone scm connection as a server that can be hit during a build. The token could then be injected into the build step and used. This particular plugin could be a case of that. It could also work for something like a status update so that could be a plugin.

@counterbeing
Copy link

@tboerger Maybe I'm misunderstanding something, but it sounds like i can use a deploy key in place of a password. I'm trying to do so like this:

  - name: publish
    image: plugins/gh-pages
    settings:
      username: counterbeing
      password:
        from_secret: github_deploy_key
      pages_directory: rendered_assets

I've added the secret to the drone project, and i've enabled write access on the deploy key. For some reason I'm hitting this:

fatal: could not read Username for 'https://github.com': No such device or address
--
484 | 2019/04/29 05:29:38 failed to push changes: exit status 128

Any thoughts on why that might be?

@bradrydzewski
Copy link
Member Author

bradrydzewski commented Apr 29, 2019

I have never used this particular plugin, but I can say that when using a token for git operations you need to use the token as the username, and x-oauth-basic as the password. So maybe try this:

  - name: publish
    image: plugins/gh-pages
    settings:
-     username: counterbeing
-     password:
-       from_secret: github_deploy_key
+     username:
+       from_secret: github_deploy_key
+     password: x-oauth-basic
      pages_directory: rendered_assets

@counterbeing
Copy link

Thanks @bradrydzewski for the quick response! That still failed with the same error though.

@bradrydzewski
Copy link
Member Author

bradrydzewski commented Apr 29, 2019

I would also point out that, I believe, deployment keys can only be used to clone code. They cannot be used to push code, which is required of this plugin. Perhaps try using a personal token instead?

EDIT looks like deploy keys can be used to push code if you check the "write access" checkbox. If you have already enabled write access, the next step to debug would be to run the plugin locally and test out your configuration, examining the source if necessary. For instructions to run locally see https://github.com/drone-plugins/drone-gh-pages#usage

@counterbeing
Copy link

counterbeing commented Apr 29, 2019

When adding a key there is a checkbox to enable pushing. I was sure to check it.

I think it may be that the repo is cloned via https, but needs to be uploaded via ssh to use the key. I may need to set the url to use ssh. If i figure it out i'll post again.

Edit: you beat me to it.

@bradrydzewski
Copy link
Member Author

bradrydzewski commented Apr 29, 2019

ah yes, the username and password fields are for username/password/api tokens, not ssh keys. So that explains why this was not working. If you want to use the plugin with an ssh key it should look something like this:

  - name: publish
    image: plugins/gh-pages
    settings:
      ssh_key:
        from_secret: github_deploy_key
      pages_directory: rendered_assets

In terms of using the ssh clone address, there is a remote_url option.

@amq
Copy link

amq commented May 4, 2019

@bradrydzewski this is not working for me.

Tried:

- name: publish  
  image: plugins/gh-pages
  settings:
    pages_directory: public/
    ssh_key:
      from_secret: github_ssh_key

and:

- name: publish  
  image: plugins/gh-pages
  settings:
    pages_directory: public/
    remote_url: git@github.com:org/repo.git
    ssh_key:
      from_secret: github_ssh_key

and:

- name: publish  
  image: plugins/gh-pages
  environment:
    DRONE_REMOTE_URL: "git@github.com:org/repo.git"
  settings:
    pages_directory: public/
    ssh_key:
      from_secret: github_ssh_key

Tried adding the SSH key in repository and profile.

In all cases:

fatal: could not read Username for 'https://github.com': No such device or address
failed to push changes: exit status 128 

I think the problem is that the remote url doesn't get modified.

@vioao
Copy link

vioao commented Jun 22, 2019

@bradrydzewski
How to set remote_url in pipelines step,it seems that it doesn't work well.

@safaci2000
Copy link
Contributor

safaci2000 commented Feb 27, 2021

If you want to use the token, all I did was set it as the value for my password secret and it work flawlessly.

Create a Github personal token, populated your environment variable where the gh_password=TOKEN then all I did was have something along these lines in my config.

- name: publish
  image: plugins/gh-pages
  settings:
    username:
      from_secret: gh_username
    password:
      from_secret: gh_password

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants