|
1 |
| -# ssh-agent |
2 |
| -GitHub Action to setup `ssh-agent` with a private key and host verification |
| 1 | +# apter-tech/ssh-agent |
| 2 | + |
| 3 | +An advanced extension of [webfactory/ssh-agent](https://github.com/webfactory/ssh-agent) that not only manages SSH private key loading but also handles SSH host verification by setting up and cleaning `known_hosts`. This action simplifies secure communication in your workflows by automating host key management with enhanced security checks. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **SSH Agent Integration**: Extends `webfactory/ssh-agent` to load SSH private keys seamlessly. |
| 10 | +- **Host Verification**: |
| 11 | + - Automatically fetches SSH host keys using `ssh-keyscan`. |
| 12 | + - Supports predefined `known_hosts` entries. |
| 13 | + - Warns about potential security risks for unverified keys. |
| 14 | +- **Key Type Filtering**: Optionally specify the types of keys to fetch (`ecdsa`, `ed25519`, etc.). |
| 15 | +- **Post-Job Cleanup**: Automatically removes added host entries after the job completes. |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +Here’s how to integrate the `apter-tech/ssh-agent` action into your GitHub workflows: |
| 22 | + |
| 23 | +### Basic Example |
| 24 | + |
| 25 | +```yaml |
| 26 | +name: Example Workflow |
| 27 | +on: [push, pull_request] |
| 28 | + |
| 29 | +jobs: |
| 30 | + example: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + steps: |
| 33 | + - name: Checkout repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + - name: Setup SSH Agent and Host Verification |
| 36 | + uses: apter-tech/ssh-agent@v1 |
| 37 | + with: |
| 38 | + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 39 | + ssh-host: github.com |
| 40 | + ssh-key-type: ed25519 |
| 41 | +``` |
| 42 | +
|
| 43 | +## Inputs |
| 44 | +
|
| 45 | +### New Inputs |
| 46 | +
|
| 47 | +| Name | Description | Required | Default | |
| 48 | +|-------------------|-----------------------------------------------------------------------------------------------------------|-----------|---------------| |
| 49 | +| ssh-host | Hostname to fetch SSH keys from using `ssh-keyscan`. | No | | |
| 50 | +| ssh-key-type | Specify the type of key to fetch. Possible values: `ecdsa`, `ed25519`, `ecdsa-sk`, `ed25519-sk`, `rsa`. | No | All types | |
| 51 | +| ssh-known-hosts | Predefined `known_hosts` entries. If provided, skips `ssh-keyscan`. | No | | |
| 52 | + |
| 53 | +### Inherited Inputs from `webfactory/ssh-agent` |
| 54 | + |
| 55 | +| Name | Description | Required | Default | |
| 56 | +|--------------------|-------------------------------------------------|----------|---------| |
| 57 | +| `ssh-private-key` | Private SSH key to register in the SSH agent. | Yes | | |
| 58 | +| `ssh-auth-sock` | Location of the SSH agent auth socket. | No | | |
| 59 | +| `log-public-key` | Log public key fingerprints. | No | true | |
| 60 | +| `ssh-agent-cmd` | Command to start the SSH agent. | No | | |
| 61 | +| `ssh-add-cmd` | Command to add the SSH key to the agent. | No | | |
| 62 | +| `git-cmd` | Command to use for Git operations. | No | | |
| 63 | + |
| 64 | +## Security Considerations |
| 65 | + |
| 66 | +### Host Key Verification |
| 67 | +- **Recommended:** Always verify host keys manually before using `ssh-keyscan`. |
| 68 | +- **Warnings:** The action emits warnings if unverified host keys are used, as they pose a risk of man-in-the-middle attacks. |
| 69 | + |
| 70 | +## How It Works |
| 71 | + |
| 72 | +**1. Main Workflow:** |
| 73 | + |
| 74 | +- Loads the SSH private key using `webfactory/ssh-agent`. |
| 75 | +- Configures `known_hosts`: |
| 76 | + - Uses predefined entries if `ssh-known-hosts` is set. |
| 77 | + - Fetches host keys using `ssh-keyscan` if `ssh-host` is provided. |
| 78 | + |
| 79 | +**2. Post-Job Cleanup:** |
| 80 | + |
| 81 | +- Removes the last added entry from known_hosts to keep the environment clean. |
| 82 | + |
| 83 | +## Example with Predefined Known Hosts |
| 84 | + |
| 85 | +```yaml |
| 86 | +- name: Setup SSH Agent with Predefined Known Hosts |
| 87 | + uses: apter-tech/ssh-agent@v1 |
| 88 | + with: |
| 89 | + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} |
| 90 | + ssh-known-hosts: | |
| 91 | + github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGh4DoiJkCQJklXG3zjGhheklNSklai38skjdjz89 |
| 92 | +``` |
| 93 | + |
| 94 | +## Development |
| 95 | + |
| 96 | +### Scripts Overview |
| 97 | +- `action.sh`: Main script for handling SSH host setup. |
| 98 | +- `post_action.sh`: Cleanup script to remove temporary host entries. |
| 99 | + |
| 100 | +## Contributing |
| 101 | + |
| 102 | +Contributions are welcome! Please open issues or submit pull requests to improve the functionality or documentation. |
| 103 | + |
| 104 | +## License |
| 105 | + |
| 106 | +This project is licensed under the MIT License. See [LICENSE](LICENSE) for details. |
0 commit comments