Authenticate with GitHub using a token

后端 未结 10 541
广开言路
广开言路 2020-11-30 17:09

I am trying to authenticate with GitHub using a personal access token. In the help files at github, it states to use the cURL method to authenticate (https://help.github.com

10条回答
  •  萌比男神i
    2020-11-30 17:11

    To avoid handing over "the keys to the castle"...

    Note that sigmavirus24's response requires you to give Travis a token with fairly wide permissions -- since GitHub only offers tokens with wide scopes like "write all my public repos" or "write all my private repos".

    If you want to tighten down access (with a bit more work!) you can use GitHub deployment keys combined with Travis encrypted yaml fields.

    Here's a sketch of how the technique works...

    First generate an RSA deploy key (via ssh-keygen) called my_key and add it as a deploy key in your github repo settings.

    Then...

    $ password=`openssl rand -hex 32`
    $ cat my_key | openssl aes-256-cbc -k "$password" -a  > my_key.enc
    $ travis encrypt --add password=$password -r my-github-user/my-repo
    

    Then use the $password file to decrypt your deploy key at integration-time, by adding to your yaml file:

    before_script: 
      - openssl aes-256-cbc -k "$password" -d -a -in my_key.enc -out my_deploy_key
      - echo -e "Host github.com\n  IdentityFile /path/to/my_deploy_key" > ~/.ssh/config
      - echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" > ~/.ssh/known_hosts
    

    Note: the last line pre-populates github's RSA key, which avoids the need for manually accepting at the time of a connection.

提交回复
热议问题