Compare commits

..
22 changed files with 102 additions and 452 deletions
-5
View File
@@ -1,5 +0,0 @@
Dockerfile
LICENSE
*.md
.git*
.github*
-15
View File
@@ -1,15 +0,0 @@
root = true
[*]
charset = utf-8
end_of_line = lf
tab_width = 4
indent_size = 4
indent_style = space
max_line_length = 9999
insert_final_newline = true
trim_trailing_whitespace = true
[*.{yml,yaml}]
tab_width = 2
indent_size = 2
-1
View File
@@ -1 +0,0 @@
github: [burnett01]
-4
View File
@@ -4,7 +4,3 @@ updates:
directory: / directory: /
schedule: schedule:
interval: monthly interval: monthly
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
@@ -23,7 +23,7 @@ jobs:
name: Test BATS Suite name: Test BATS Suite
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Install BATS - name: Install BATS
run: | run: |
@@ -38,7 +38,7 @@ jobs:
name: Validate Action Definition name: Validate Action Definition
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Validate action.yml - name: Validate action.yml
run: | run: |
@@ -81,7 +81,7 @@ jobs:
needs: [validate-action, action-structure] needs: [validate-action, action-structure]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Build Docker image - name: Build Docker image
run: | run: |
@@ -94,7 +94,7 @@ jobs:
name: Validate Action Structure name: Validate Action Structure
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Check required files - name: Check required files
run: | run: |
@@ -128,7 +128,7 @@ jobs:
name: Lint Shell Scripts name: Lint Shell Scripts
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Install ShellCheck - name: Install ShellCheck
run: | run: |
@@ -151,7 +151,7 @@ jobs:
needs: [test, validate-action, docker-build, action-structure, lint-shell] needs: [test, validate-action, docker-build, action-structure, lint-shell]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v7 uses: actions/checkout@v4
- name: Final integration check - name: Final integration check
run: | run: |
@@ -19,7 +19,7 @@ jobs:
actions: read actions: read
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v4
- name: Build a Docker image - name: Build a Docker image
run: docker build -t burnett01/rsync-deployments . run: docker build -t burnett01/rsync-deployments .
- name: Run Snyk to check Docker image for vulnerabilities - name: Run Snyk to check Docker image for vulnerabilities
@@ -30,12 +30,7 @@ jobs:
with: with:
image: burnett01/rsync-deployments image: burnett01/rsync-deployments
args: --file=Dockerfile args: --file=Dockerfile
- name: Output sarif file
run: cat snyk.sarif
- name: fix security-severity "null" to "0" for valid sarif format
run: |
sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif
- name: Upload result to GitHub Code Scanning - name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v4 uses: github/codeql-action/upload-sarif@v3
with: with:
sarif_file: snyk.sarif sarif_file: snyk.sarif
+5 -8
View File
@@ -1,14 +1,11 @@
FROM alpine:3.24.1@sha256:28bd5fe8b56d1bd048e5babf5b10710ebe0bae67db86916198a6eec434943f8b AS base # drinternet/rsync@v1.5.1
FROM drinternet/rsync@sha256:e61f4047577b566872764fa39299092adeab691efb3884248dbd6495dc926527
RUN apk update && apk add --no-cache --upgrade rsync openssh openssl busybox
# always force-upgrade rsync to get the latest security fixes
RUN apk update && apk add --no-cache --upgrade rsync
RUN rm -rf /var/cache/apk/* RUN rm -rf /var/cache/apk/*
COPY docker-rsync/* /bin/ # Copy entrypoint
RUN chmod +x /bin/agent-* /bin/ssh-* /bin/hosts-*
FROM base AS build
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
+1 -2
View File
@@ -1,8 +1,7 @@
MIT License MIT License
Copyright (c) 2019-2022 Contention Copyright (c) 2019-2022 Contention
Copyright (c) 2019-2026 Joshua Piper (Dr Internet) Copyright (c) 2019-2025 Burnett01
Copyright (c) 2019-2026 Burnett01
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
+57 -122
View File
@@ -6,65 +6,24 @@
[![Dependabot Updates](https://github.com/Burnett01/rsync-deployments/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/Burnett01/rsync-deployments/actions/workflows/dependabot/dependabot-updates) [![Dependabot Updates](https://github.com/Burnett01/rsync-deployments/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/Burnett01/rsync-deployments/actions/workflows/dependabot/dependabot-updates)
This cross-platform GitHub Action deploys files in [`path`](#inputs) (relative to `GITHUB_WORKSPACE`) to a remote folder via rsync over ssh. This GitHub Action (amd64) deploys files in `GITHUB_WORKSPACE` to a remote folder via rsync over ssh.
Use this action in a CD workflow which leaves deployable code in `GITHUB_WORKSPACE`, such [actions/checkout](https://github.com/actions/checkout). Use this action in a CD workflow which leaves deployable code in `GITHUB_WORKSPACE`.
The base-image of this action is very small and based on **Alpine 3.24.1** (no cache) which results in fast deployments. The base-image [drinternet/rsync](https://github.com/JoshPiper/rsync-docker/) of this action is very small and is based on Alpine 3.22.1 (no cache) which results in fast deployments.
Alpine version: [3.24.1](https://www.alpinelinux.org/posts/Alpine-3.24.1-released.html) Alpine version: [3.22.1](https://alpinelinux.org/posts/Alpine-3.19.8-3.20.7-3.21.4-3.22.1-released.html)
Rsync version: [3.4.3-r1](https://download.samba.org/pub/rsync/NEWS#3.4.3) Rsync version: [3.4.1-r0](https://download.samba.org/pub/rsync/NEWS#3.4.1)
## Current Version: v9 (9.0.0)
### Release channels:
| Version | Purpose | Immutable |
| ------- | ------------------ | ------------------ |
| ``v9`` (recommended, LTS) | latest MAJOR (pointer to 9.MINOR.PATCH) | no |
| 9.0.0 | latest MAJOR+MINOR+PATCH | yes |
| ``v8`` (ESU) | previous MAJOR (pointer to 8.MINOR.PATCH) | no |
| 8.0.5 | previous MAJOR+MINOR+PATCH | yes |
Check [SECURITY.md](SECURITY.md) for support cycles.
--- ---
## How it works
```yml
name: DEPLOY
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: rsync deployments
uses: burnett01/rsync-deployments@v9
with:
switches: -avzr --delete
path: src/
remote_path: ${{ secrets.REMOTE_PATH }} # ex: /var/www/html/
remote_host: ${{ secrets.REMOTE_HOST }} # ex: example.com
remote_port: ${{ secrets.REMOTE_PORT }} # ex: 22
remote_user: ${{ secrets.REMOTE_USER }} # ex: ubuntu
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
```
## Inputs ## Inputs
- `debug`* - Whether to enable debug output. ("true" / "false") - Default: "false"
- `switches`* - The first is for any initial/required rsync flags, eg: `-avzr --delete` - `switches`* - The first is for any initial/required rsync flags, eg: `-avzr --delete`
- `rsh` - Remote shell commands - `rsh` - Remote shell commands
- `strict_hostkeys_checking` - Enables support for strict hostkeys (fingerprint) checking. ("true" / "false") - Default: "false" - `legacy_allow_rsa_hostkeys` - Enables support for legacy RSA host keys on OpenSSH 8.8+. ("true" / "false")
- `legacy_allow_rsa_hostkeys` - Enables support for legacy RSA host keys on OpenSSH 8.8+. ("true" / "false") - Default: "false"
- `path` - The source path. Defaults to GITHUB_WORKSPACE and is relative to it - `path` - The source path. Defaults to GITHUB_WORKSPACE and is relative to it
@@ -90,9 +49,9 @@ This action needs secret variables for the ssh private key of your key pair. The
For simplicity, we are using `REMOTE_*` as the secret variables throughout the examples. For simplicity, we are using `REMOTE_*` as the secret variables throughout the examples.
## Example usage ## Current Version: 7.1.0
For better **security** always use secrets for remote_host, remote_port, remote_user and remote_path inputs. ## Example usage
Simple: Simple:
@@ -107,36 +66,55 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v3
- name: rsync deployments - name: rsync deployments
uses: burnett01/rsync-deployments@v9 uses: burnett01/rsync-deployments@7.1.0
with: with:
switches: -avzr --delete switches: -avzr --delete
path: src/ path: src/
remote_path: ${{ secrets.REMOTE_PATH }} # ex: /var/www/html/ remote_path: /var/www/html/
remote_host: ${{ secrets.REMOTE_HOST }} # ex: example.com remote_host: example.com
remote_port: ${{ secrets.REMOTE_PORT }} # ex: 22 remote_user: debian
remote_user: ${{ secrets.REMOTE_USER }} # ex: ubuntu
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }} remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
``` ```
Advanced (with filters etc): Advanced:
```yml ```yml
jobs: jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v3
- name: rsync deployments - name: rsync deployments
uses: burnett01/rsync-deployments@v9 uses: burnett01/rsync-deployments@7.1.0
with: with:
switches: -avzr --delete --exclude="" --include="" --filter="" switches: -avzr --delete --exclude="" --include="" --filter=""
path: src/ path: src/
remote_path: ${{ secrets.REMOTE_PATH }} # ex: /var/www/html/ remote_path: /var/www/html/
remote_host: ${{ secrets.REMOTE_HOST }} # ex: example.com remote_host: example.com
remote_port: ${{ secrets.REMOTE_PORT }} # ex: 22 remote_port: 5555
remote_user: ${{ secrets.REMOTE_USER }} # ex: ubuntu remote_user: debian
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
```
For better **security**, I suggest you create additional secrets for remote_host, remote_port, remote_user and remote_path inputs.
```yml
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: rsync deployments
uses: burnett01/rsync-deployments@7.1.0
with:
switches: -avzr --delete
path: src/
remote_path: ${{ secrets.REMOTE_PATH }}
remote_host: ${{ secrets.REMOTE_HOST }}
remote_port: ${{ secrets.REMOTE_PORT }}
remote_user: ${{ secrets.REMOTE_USER }}
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }} remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
``` ```
@@ -147,16 +125,16 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v3
- name: rsync deployments - name: rsync deployments
uses: burnett01/rsync-deployments@v9 uses: burnett01/rsync-deployments@7.1.0
with: with:
switches: -avzr --delete switches: -avzr --delete
path: src/ path: src/
remote_path: ${{ secrets.REMOTE_PATH }} # ex: /var/www/html/ remote_path: ${{ secrets.REMOTE_PATH }}
remote_host: ${{ secrets.REMOTE_HOST }} # ex: example.com remote_host: ${{ secrets.REMOTE_HOST }}
remote_port: ${{ secrets.REMOTE_PORT }} # ex: 22 remote_port: ${{ secrets.REMOTE_PORT }}
remote_user: ${{ secrets.REMOTE_USER }} # ex: ubuntu remote_user: ${{ secrets.REMOTE_USER }}
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }} remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
remote_key_pass: ${{ secrets.REMOTE_PRIVATE_KEY_PASS }} remote_key_pass: ${{ secrets.REMOTE_PRIVATE_KEY_PASS }}
``` ```
@@ -173,17 +151,17 @@ jobs:
deploy: deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v3
- name: rsync deployments - name: rsync deployments
uses: burnett01/rsync-deployments@v9 uses: burnett01/rsync-deployments@7.1.0
with: with:
switches: -avzr --delete switches: -avzr --delete
legacy_allow_rsa_hostkeys: "true" legacy_allow_rsa_hostkeys: "true"
path: src/ path: src/
remote_path: ${{ secrets.REMOTE_PATH }} # ex: /var/www/html/ remote_path: ${{ secrets.REMOTE_PATH }}
remote_host: ${{ secrets.REMOTE_HOST }} # ex: example.com remote_host: ${{ secrets.REMOTE_HOST }}
remote_port: ${{ secrets.REMOTE_PORT }} # ex: 22 remote_port: ${{ secrets.REMOTE_PORT }}
remote_user: ${{ secrets.REMOTE_USER }} # ex: ubuntu remote_user: ${{ secrets.REMOTE_USER }}
remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }} remote_key: ${{ secrets.REMOTE_PRIVATE_KEY }}
``` ```
@@ -285,63 +263,20 @@ sudo apk add rsync
## Versions ## Versions
## Version 8.0.5 ## Version 7.0.2
Check here: Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.5 (alpine 3.23.4) - https://github.com/Burnett01/rsync-deployments/tree/7.0.2 (alpine 3.19.1)
## Version 8.0.4
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.4 (alpine 3.23.3)
## Version 8.0.3
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.3 (alpine 3.23.2)
## Version 8.0.2
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.2 (alpine 3.23.0)
## Version 8.0.1 (EOL)
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.1 (alpine 3.23.0)
## Version 8.0.0 (EOL due to regression -> fixed via 8.0.1 & 8.0.2)
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/8.0.0 (alpine 3.23.0)
## Version 7.1.0 (EOL)
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/7.1.0 (alpine 3.22.1)
## Version 7.0.2 (EOL)
Check here:
- https://github.com/Burnett01/rsync-deployments/tree/7.0.2 (alpine 3.22.1)
--- ---
## Version 7.0.0 & 7.0.1 (EOL) ## Version 7.0.0 & 7.0.1 (DEPRECATED)
Check here: Check here:
- https://github.com/Burnett01/rsync-deployments/tree/7.0.0 (alpine 3.19.1) - https://github.com/Burnett01/rsync-deployments/tree/7.0.0 (alpine 3.19.1)
- https://github.com/Burnett01/rsync-deployments/tree/7.0.1 (alpine 3.22.1) - https://github.com/Burnett01/rsync-deployments/tree/7.0.1 (alpine 3.19.1)
--- ---
@@ -402,7 +337,7 @@ Please note that version 1.0 has reached end of life state.
## Acknowledgements ## Acknowledgements
+ This project is a fork of [Contention/rsync-deployments](https://github.com/Contention/rsync-deployments) + This project is a fork of [Contention/rsync-deployments](https://github.com/Contention/rsync-deployments)
+ docker-rsync [JoshPiper/rsync-docker](https://github.com/JoshPiper/rsync-docker) + Base image [JoshPiper/rsync-docker](https://github.com/JoshPiper/rsync-docker)
--- ---
+12 -27
View File
@@ -1,36 +1,21 @@
# Security Policy # Security Policy
The Docker image and code quality are regularly checked for vulnerabilities and CVEs by Snyk and CodeQL.
## Supported Versions ## Supported Versions
The following versions are currently being supported with security updates: The following versions are currently being supported with security updates:
| Version | Supported | Rsync version | Alpine version | Support Until | | Version | Supported | Rsync version |
| ------- | ------------------ | ------------------ | ------------------ | ------------------ | | ------- | ------------------ | ------------------ |
| (``v9``) 9.0.0 | :white_check_mark: | >= 3.4.3-r1 | 3.24.1 | LTS (2028-*) | | 7.1.0 | :white_check_mark: | >= 3.4.1 |
| (``v8``) 8.0.5 | :white_check_mark: | >= 3.4.1-r1 | 3.23.4 | ESU (Apr, 1st 2027) | | 7.0.2 | :white_check_mark: | >= 3.4.0 |
| 8.0.4 | :white_check_mark: | >= 3.4.1-r1 | 3.23.3 | Dec, 6th 2026 | | 7.0.1 | :warning: DEPRECATED | < 3.4.0 |
| 8.0.3 | :white_check_mark: | >= 3.4.1-r1 | 3.23.2 | Dec, 6th 2026 | | 7.0.0 | :warning: DEPRECATED | < 3.4.0|
| 8.0.2 | :white_check_mark: | >= 3.4.1-r1 | 3.23.0 | Dec, 6th 2026 | | 6.x | :x: EOL |< 3.4.0|
| 8.0.1 | :x: EOL | >= 3.4.1-r1 | 3.23.0 | † Apr, 1st 2026 | | 5.x | :x: EOL |< 3.4.0|
| 8.0.0 | :x: EOL (due to regression #90) | >= 3.4.1-r1 | 3.23.0 | † Dec, 6th 2025 | | 4.x | :x: EOL |< 3.4.0|
| 7.1.0 | :x: EOL | >= 3.4.1-r0 | 3.22.1 | † June, 1st 2026 ([deprecation notice](https://github.com/Burnett01/rsync-deployments/discussions/96)) | | 3.0 | :x: EOL |< 3.4.0|
| 7.0.2 | :x: EOL | >= 3.4.0-r0 | 3.22.1 | † June, 1st 2026 ([deprecation notice](https://github.com/Burnett01/rsync-deployments/discussions/96)) | | 2.0 | :x: EOL |< 3.4.0|
| 7.0.1 | :x: EOL | < 3.4.0 | 3.22.1 | † Dec, 6th 2025 | | 1.0 | :x: EOL |< 3.4.0|
| 7.0.0 | :x: EOL | < 3.4.0| 3.19.1 | † Dec, 6th 2025 |
| 6.x | :x: EOL |< 3.4.0| 3.17.2 | † 2024 |
| 5.x | :x: EOL |< 3.4.0| 3.11 - 3.14.1 - 3.15 - 3.16 - 3.17.2 | † 2024 |
| 4.x | :x: EOL |< 3.4.0| 3.11 | † |
| 3.0 | :x: EOL |< 3.4.0| N/A | † |
| 2.0 | :x: EOL |< 3.4.0| Ubuntu | † |
| 1.0 | :x: EOL |< 3.4.0| Ubuntu | † |
### Terminology
EOL = End of life (no support/no updates)
DEPRECATED = Close to EOL (support/no updates)
## Reporting a Vulnerability ## Reporting a Vulnerability
+1 -9
View File
@@ -1,5 +1,5 @@
name: 'Rsync Deployments Action' name: 'Rsync Deployments Action'
description: 'GitHub Action for deploying code via rsync over ssh securely - used by 5k+ workflows!' description: 'GitHub Action for deploying code via rsync over ssh'
author: 'Burnett01' author: 'Burnett01'
inputs: inputs:
switches: switches:
@@ -13,10 +13,6 @@ inputs:
description: 'Enables support for legacy RSA host keys on OpenSSH 8.8+' description: 'Enables support for legacy RSA host keys on OpenSSH 8.8+'
required: false required: false
default: 'false' default: 'false'
strict_hostkeys_checking:
description: 'Controls strict host keys checking'
required: false
default: 'false'
path: path:
description: 'The local path' description: 'The local path'
required: false required: false
@@ -41,10 +37,6 @@ inputs:
description: 'The remote key passphrase' description: 'The remote key passphrase'
required: false required: false
default: '' default: ''
debug:
description: 'Debug the action'
required: false
default: 'false'
runs: runs:
using: 'docker' using: 'docker'
image: 'Dockerfile' image: 'Dockerfile'
-40
View File
@@ -1,40 +0,0 @@
# Scripts
Shell-scripts to help with managing SSH agents and known hosts files.
### SSH Management
#### ssh-init
This command create the ``$HOME/.ssh`` folder with default permissions ``700``.
### SSH-Agent Management
#### agent-start
This command starts the SSH agent, if it isn't already started (SSH_AGENT_PID set or ssh agent ID file found).
It takes one optional argument, for the name of the agent to be started. Defaults to "default".
This program needs to be source'd to work correctly.
`source agent-start "default"`
#### agent-stop
This command stops the SSH agent, if it is started (SSH_AGENT_PID set or ssh agent ID file found).
It takes one optional argument, for the name of the agent to be stopped. Defaults to "default".
`agent-stop "my-agent-name"`
#### agent-add
This command adds a key to the currently running SSH agent. The key is taken from stdin, and the agent used is that in SSH_AGENT_PID.
#### agent-askpass
This command is called by ssh-add when the [SSH_ASKPASS](https://man.openbsd.org/ssh-add.1#ENVIRONMENT) variable is set active. The command returns the SSH_PASS to [ssh-askpass(1)](https://man.openbsd.org/ssh-askpass.1).
This command is ignored by ssh-add if the key does not require a passphrase.
### known_hosts management
#### hosts-init
This command creates the known_hosts file (``$HOME/.ssh/known_hosts``) with default permission ``600``.
#### hosts-add
This command adds an entry to the known hosts file, and ensures its permissions are correct. It takes one argument, which is the new key to add.
#### hosts-clear
This command truncates the known_hosts file.
-6
View File
@@ -1,6 +0,0 @@
#!/bin/sh
set -eu
source agent-start "${1:-default}"
cat - | tr -d '\r' | DISPLAY=1 SSH_ASKPASS=agent-askpass ssh-add - >/dev/null
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
set -eu
echo "$SSH_PASS"
-21
View File
@@ -1,21 +0,0 @@
#!/bin/sh
set -eu
FOLDER=${1:-default}
STORE_PATH="/tmp/ssh-agent/$FOLDER"
mkdir -p "$STORE_PATH"
if [ -z "${SSH_AGENT_PID:-}" ]; then
if [ -f "$STORE_PATH/id" ]; then
SSH_AGENT_PID=$(cat "$STORE_PATH/id")
export SSH_AGENT_PID
SSH_AUTH_SOCK=$(cat "$STORE_PATH/sock")
export SSH_AUTH_SOCK
else
eval "$(ssh-agent)" > /dev/null
echo "$SSH_AGENT_PID" > "$STORE_PATH"/id
echo "$SSH_AUTH_SOCK" > "$STORE_PATH"/sock
fi
fi
-37
View File
@@ -1,37 +0,0 @@
#!/bin/sh
set -eu
if [ ! -z "$SSH_AGENT_PID" ]; then
# Here, the environment is set already, just kill the script.
eval $(ssh-agent -k) >/dev/null
exit $?
else
# The env isn't set, construct the file path.
FOLDER=${1:-default}
STORE_PATH="/tmp/ssh-agent/$FOLDER"
if [ ! -d "$STORE_PATH" ]; then
echo "Store Path $STORE_PATH doesn't exist!" >&2
exit 1
fi
# And check our files exist.
if [ -f "$STORE_PATH/id" ]; then
# Grab our PID and socket.
SSH_AGENT_PID=$(cat "$STORE_PATH/id")
export SSH_AGENT_PID
rm "$STORE_PATH/id"
SSH_AUTH_SOCK=$(cat "$STORE_PATH/sock")
export SSH_AUTH_SOCK
rm "$STORE_PATH/sock"
rmdir "$STORE_PATH"
eval $(ssh-agent -k) >/dev/null
exit $?
else
echo "SSH_AGENT_PID not set, $STORE_PATH/id doesn't exist!" >&2
exit 1
fi
fi
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
set -eu
echo "$@" >> $HOME/.ssh/known_hosts
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
set -eu
truncate -s 0 $HOME/.ssh/known_hosts
-9
View File
@@ -1,9 +0,0 @@
#!/bin/sh
set -eu
if [ ! -f "$HOME/.ssh/known_hosts" ]; then
touch $HOME/.ssh/known_hosts
fi
chmod 600 $HOME/.ssh/known_hosts
-7
View File
@@ -1,7 +0,0 @@
#!/bin/sh
set -eu
if [ ! -d "$HOME/.ssh" ]; then
mkdir -m 700 $HOME/.ssh
fi
+8 -38
View File
@@ -1,55 +1,25 @@
#!/bin/sh #!/bin/sh
set -eu
if [ "${INPUT_DEBUG:-false}" = "true" ]; then
set -x
fi
if [ -z "$(echo "$INPUT_REMOTE_PATH" | awk '{$1=$1};1')" ]; then if [ -z "$(echo "$INPUT_REMOTE_PATH" | awk '{$1=$1};1')" ]; then
echo "The remote_path can not be empty. see: github.com/Burnett01/rsync-deployments/issues/44" echo "The remote_path can not be empty. see: github.com/Burnett01/rsync-deployments/issues/44"
exit 1 exit 1
fi fi
# Initialize SSH and known hosts.
source ssh-init
source hosts-init
# Start the SSH agent and load key. # Start the SSH agent and load key.
source agent-start "$GITHUB_ACTION" source agent-start "$GITHUB_ACTION"
echo "$INPUT_REMOTE_KEY" | SSH_PASS="$INPUT_REMOTE_KEY_PASS" agent-add echo "$INPUT_REMOTE_KEY" | SSH_PASS="$INPUT_REMOTE_KEY_PASS" agent-add
# Add strict errors.
set -eu
# Variables. # Variables.
LEGACY_RSA_HOSTKEYS="" LEGACY_RSA_HOSTKEYS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
if [ "${INPUT_LEGACY_ALLOW_RSA_HOSTKEYS:-false}" = "true" ]; then LEGACY_RSA_HOSTKEYS=$([ "$INPUT_LEGACY_ALLOW_RSA_HOSTKEYS" = "true" ] && echo "$LEGACY_RSA_HOSTKEYS" || echo "")
LEGACY_RSA_HOSTKEYS="-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa"
fi
STRICT_HOSTKEYS_CHECKING="-o StrictHostKeyChecking=no" SWITCHES="$INPUT_SWITCHES"
if [ "${INPUT_STRICT_HOSTKEYS_CHECKING:-false}" = "true" ]; then RSH="ssh -o StrictHostKeyChecking=no $LEGACY_RSA_HOSTKEYS -p $INPUT_REMOTE_PORT $INPUT_RSH"
STRICT_HOSTKEYS_CHECKING="-o UserKnownHostsFile=$HOME/.ssh/known_hosts -o StrictHostKeyChecking=yes"
key="$(ssh-keyscan -p "$INPUT_REMOTE_PORT" "$INPUT_REMOTE_HOST" 2>/dev/null | sed '/^#/d')" || key=""
if [ -n "$key" ]; then
# fingerprint verification
echo "$key" | ssh-keygen -lf -
# add to known hosts
echo "$key" | while IFS= read -r line; do hosts-add "$line"; done
else
echo "Warning: failed to fetch host key for $INPUT_REMOTE_HOST" >&2
exit 1
fi
fi
RSH="ssh $STRICT_HOSTKEYS_CHECKING $LEGACY_RSA_HOSTKEYS -p $INPUT_REMOTE_PORT $INPUT_RSH"
LOCAL_PATH="$GITHUB_WORKSPACE/$INPUT_PATH" LOCAL_PATH="$GITHUB_WORKSPACE/$INPUT_PATH"
DSN="$INPUT_REMOTE_USER@$INPUT_REMOTE_HOST" DSN="$INPUT_REMOTE_USER@$INPUT_REMOTE_HOST"
# Deploy. # Deploy.
sh -c "rsync $INPUT_SWITCHES -e '$RSH' $LOCAL_PATH $DSN:$INPUT_REMOTE_PATH" sh -c "rsync $SWITCHES -e '$RSH' $LOCAL_PATH $DSN:$INPUT_REMOTE_PATH"
# Clean up.
source agent-stop "$GITHUB_ACTION"
source hosts-clear
exit 0
+10 -73
View File
@@ -1,13 +1,12 @@
#!/usr/bin/env bats #!/usr/bin/env bats
setup() { setup() {
# Create dummy binaries for sourcing # Create a dummy ssh agent and agent-add for sourcing
echo 'echo "source"' > source
echo 'echo "agent started"' > agent-start echo 'echo "agent started"' > agent-start
echo 'echo "key added"' > agent-add echo 'echo "key added"' > agent-add
chmod +x source agent-start agent-add chmod +x agent-start agent-add
# Create dummy rsync binary to capture its arguments # Create a dummy rsync to capture its arguments
echo 'echo "rsync $@"' > rsync echo 'echo "rsync $@"' > rsync
chmod +x rsync chmod +x rsync
@@ -15,7 +14,7 @@ setup() {
} }
teardown() { teardown() {
rm -f source agent-start agent-add rsync ssh-keyscan hosts-add rm -f agent-start agent-add rsync
} }
@test "fails if INPUT_REMOTE_PATH is empty" { @test "fails if INPUT_REMOTE_PATH is empty" {
@@ -36,14 +35,13 @@ teardown() {
export INPUT_RSH="" export INPUT_RSH=""
export INPUT_PATH="" export INPUT_PATH=""
export INPUT_REMOTE_USER="user" export INPUT_REMOTE_USER="user"
export INPUT_REMOTE_HOST="localhost.local" export INPUT_REMOTE_HOST="host"
export GITHUB_WORKSPACE="/tmp" export GITHUB_WORKSPACE="/tmp"
export DSN="user@localhost.local" export DSN="user@host"
export LOCAL_PATH="/tmp/" export LOCAL_PATH="/tmp/"
run ./entrypoint.sh run ./entrypoint.sh
[[ "${output}" == *"HostKeyAlgorithms=+ssh-rsa"* ]]
[[ "${output}" == *"rsync -avz -e ssh -o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 22 /tmp/ user@localhost.local:remote/"* ]]
} }
@test "does not include legacy RSA switches when not allowed" { @test "does not include legacy RSA switches when not allowed" {
@@ -57,72 +55,11 @@ teardown() {
export INPUT_RSH="" export INPUT_RSH=""
export INPUT_PATH="" export INPUT_PATH=""
export INPUT_REMOTE_USER="user" export INPUT_REMOTE_USER="user"
export INPUT_REMOTE_HOST="localhost.local" export INPUT_REMOTE_HOST="host"
export GITHUB_WORKSPACE="/tmp" export GITHUB_WORKSPACE="/tmp"
export DSN="user@localhost.local" export DSN="user@host"
export LOCAL_PATH="/tmp/" export LOCAL_PATH="/tmp/"
run ./entrypoint.sh run ./entrypoint.sh
[[ "${output}" == *"rsync -avz -e ssh -o StrictHostKeyChecking=no -p 22 /tmp/ user@localhost.local:remote/"* ]] [[ "${output}" != *"HostKeyAlgorithms=+ssh-rsa"* ]]
}
@test "includes STRICT_HOSTKEYS_CHECKING switches when allowed" {
# Set a fake HOME dir
local -r HOME="/tmp"
export INPUT_LEGACY_ALLOW_RSA_HOSTKEYS="false"
export INPUT_STRICT_HOSTKEYS_CHECKING="true"
export INPUT_REMOTE_PATH="remote/"
export INPUT_REMOTE_KEY="dummy"
export INPUT_REMOTE_KEY_PASS="dummy"
export GITHUB_ACTION="dummy"
export INPUT_SWITCHES="-avz"
export INPUT_REMOTE_PORT="22"
export INPUT_RSH=""
export INPUT_PATH=""
export INPUT_REMOTE_USER="user"
export INPUT_REMOTE_HOST="localhost.local"
export GITHUB_WORKSPACE="/tmp"
export DSN="user@localhost.local"
export LOCAL_PATH="/tmp/"
# Generate a mock key pair to test ssh-keyscan (entrypoint.sh:32)
rm -f "$HOME/mockKeyPair" "$HOME/mockKeyPair.pub" \
&& ssh-keygen -t ed25519 -f "$HOME/mockKeyPair" -N '' -q -C '' \
&& mockPublicKey=$(< "$HOME/mockKeyPair.pub")
# Create dummy ssh-keyscan binary to return $mockPublicKey
echo "echo 'localhost.local $mockPublicKey #Mock 1'" > ssh-keyscan
chmod +x ssh-keyscan
# Create dummy hosts-add binary to capture its arguments
echo 'echo "hosts-add $@"' > hosts-add
chmod +x hosts-add
run ./entrypoint.sh
[[ "${output}" == *"hosts-add localhost.local ssh-ed25519"* ]]
[[ "${output}" == *"rsync -avz -e ssh -o UserKnownHostsFile=/tmp/.ssh/known_hosts -o StrictHostKeyChecking=yes -p 22 /tmp/ user@localhost.local:remote/"* ]]
}
@test "does not includes STRICT_HOSTKEYS_CHECKING switches when not allowed" {
export INPUT_LEGACY_ALLOW_RSA_HOSTKEYS="false"
export INPUT_STRICT_HOSTKEYS_CHECKING="false"
export INPUT_REMOTE_PATH="remote/"
export INPUT_REMOTE_KEY="dummy"
export INPUT_REMOTE_KEY_PASS="dummy"
export GITHUB_ACTION="dummy"
export INPUT_SWITCHES="-avz"
export INPUT_REMOTE_PORT="22"
export INPUT_RSH=""
export INPUT_PATH=""
export INPUT_REMOTE_USER="user"
export INPUT_REMOTE_HOST="localhost.local"
export GITHUB_WORKSPACE="/tmp"
export DSN="user@localhost.local"
export LOCAL_PATH="/tmp/"
run ./entrypoint.sh
[[ "${output}" == *"rsync -avz -e ssh -o StrictHostKeyChecking=no -p 22 /tmp/ user@localhost.local:remote/"* ]]
} }