Skip to content

Commit 110052a

Browse files
authored
Merge pull request #11 from jitsecurity/sc-20043-self-hosted-runners-customer-scripts
Sc 20043 self hosted runners customer scripts
2 parents fcc49e4 + 69c6d3f commit 110052a

4 files changed

Lines changed: 147 additions & 4 deletions

File tree

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ create-teams:
2828
python3 src/utils/github_topics_to_json_file.py && \
2929
python3 src/scripts/create_teams.py teams.json
3030

31+
setup-self-hosted-runner-centos:
32+
sudo yum install -y jq && \
33+
chmod +x src/scripts/self-hosted-runners/setup-self-hosted-runner-centos.sh && \
34+
./src/scripts/self-hosted-runners/setup-self-hosted-runner-centos.sh && \
35+
chmod +x src/scripts/self-hosted-runners/install-github-runner-agent.sh && \
36+
./src/scripts/self-hosted-runners/install-github-runner-agent.sh $(token) $(github_organization)
37+
38+
3139
help:
3240
@echo "Usage: make [target]"
3341
@echo ""

README.md

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jit-customer-scripts/
1414
├── src/
1515
│ └── scripts/
1616
│ └── create_teams.py
17+
| └── self-hosted-runners
18+
│ └── setup-self-hosted-runner-centos.sh
19+
│ └── ...
1720
├── src/
1821
│ └── utils/
1922
│ └── github_topic_to_json_file.py
@@ -35,6 +38,21 @@ jit-customer-scripts/
3538

3639
- Python 3.x
3740
- Git
41+
- make
42+
43+
To make sure you have all you can run this command:
44+
45+
#### Centos
46+
47+
```shell
48+
sudo yum install -y git make && git clone https://github.com/jitsecurity/jit-customer-scripts.git && cd jit-customer-scripts
49+
```
50+
51+
#### Ubuntu
52+
53+
```shell
54+
sudo apt install -y git make && git clone https://github.com/jitsecurity/jit-customer-scripts.git && cd jit-customer-scripts
55+
```
3856

3957
## Generating API Keys
4058

@@ -85,6 +103,8 @@ Before running the script, you need to configure the necessary environment varia
85103

86104
## Usage
87105

106+
### Creating Teams from Github Topics
107+
88108
To run the script and create teams and update assets, use the following command:
89109

90110
```shell
@@ -102,9 +122,10 @@ python src/scripts/create_teams.py teams.json
102122
This command will fetch the repository names and topics from the GitHub API and generate the JSON file. And then it will
103123
create the teams and update the assets.
104124

105-
> We recommend using something like Github Actions and Github secrets to run this script on a schedule to make sure you are always synced.
125+
> We recommend using something like Github Actions and Github secrets to run this script on a schedule to make sure you
126+
> are always synced.
106127
107-
### Using External JSON File
128+
#### Using External JSON File
108129

109130
You can also provide a JSON file containing team details using a command line argument directly. The JSON file should
110131
have the following structure:
@@ -154,7 +175,7 @@ python scripts/create_teams.py path/to/teams.json
154175

155176
Replace `path/to/teams.json` with the actual path to your JSON file.
156177

157-
## Excluding Topics
178+
#### Excluding Topics
158179

159180
You can exclude certain topics from being considered when creating teams. \
160181
To exclude topics, you could add them in the `make configure` command or update this env var in
@@ -166,7 +187,24 @@ For example, to exclude topics that contain the word "test", you can set the var
166187

167188
This will exclude topics with names like "test", "test123", and "abc-testing".
168189

169-
## Development
190+
#### Development
170191

171192
To override Jit's API endpoint, you can set the `JIT_API_ENDPOINT` environment variable. If the variable is not set, the
172193
default value will be used.
194+
195+
### Settings Up Self-Hosted Runners
196+
197+
To setup self-hosted runners, use the following command:
198+
199+
You need to take the self hosted runners token from the Github Actions page of your repository.
200+
`https://github.com/<your-github-org-name>/jit/settings/actions/runners`
201+
202+
#### Running on CentOS
203+
204+
```shell
205+
make setup-self-hosted-runner-centos token=<your-token> github_organization=<your-github-org-name>
206+
```
207+
208+
You will be prompted to answer some questions about your runner. \
209+
When you complete this step, restart your EC2 machine. \
210+
The runner will be automatically started on boot.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Assigning arguments to named variables for clarity
7+
user_token="$1"
8+
github_organization="$2"
9+
10+
# Ensure both arguments are provided
11+
if [ -z "$user_token" ] || [ -z "$github_organization" ]; then
12+
echo "Usage: $0 <user_token> <github_organization>"
13+
exit 1
14+
fi
15+
16+
mkdir actions-runner && cd actions-runner
17+
curl -o actions-runner-linux-x64-2.308.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.308.0/actions-runner-linux-x64-2.308.0.tar.gz
18+
tar xzf ./actions-runner-linux-x64-2.308.0.tar.gz
19+
# Create the runner and start the configuration experience
20+
./config.sh --url "https://github.com/$github_organization/jit" --token "$user_token"
21+
22+
sudo ./svc.sh install ec2-user
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Exit on error
4+
set -e
5+
6+
# Check if script is run as root
7+
if [ "$EUID" -eq 0 ]; then
8+
echo "Please run this script as a non-root user."
9+
exit 1
10+
fi
11+
12+
# Install required packages only if they aren't already installed
13+
14+
# Check for shadow-utils
15+
if ! rpm -q shadow-utils &> /dev/null; then
16+
echo "Installing shadow-utils..."
17+
sudo yum install -y shadow-utils
18+
fi
19+
20+
# Check for curl or curl-minimal
21+
if ! rpm -q curl &> /dev/null && ! rpm -q curl-minimal &> /dev/null; then
22+
echo "Installing curl..."
23+
sudo yum install -y curl
24+
fi
25+
26+
# Check for iptables
27+
if ! rpm -q iptables &> /dev/null; then
28+
echo "Installing iptables..."
29+
sudo yum install -y iptables
30+
fi
31+
32+
# Download Docker installation script
33+
echo "Installing Docker in rootless mode..."
34+
curl -fsSL https://get.docker.com/rootless | sh
35+
36+
# Set environment variables
37+
echo "Updating environment variables..."
38+
USER_NAME=$(whoami)
39+
USER_ID=$(id -u)
40+
41+
echo "export PATH=\$PATH:/home/$USER_NAME/bin" >> ~/.bashrc
42+
echo "export DOCKER_HOST=unix:///run/user/$USER_ID/docker.sock" >> ~/.bashrc
43+
source ~/.bashrc
44+
45+
# Set up Docker as a systemd user service
46+
47+
# Create the systemd service directory and file
48+
mkdir -p ~/.config/systemd/user/
49+
cat <<EOL > ~/.config/systemd/user/docker-rootless.service
50+
[Unit]
51+
Description=Docker Rootless
52+
After=network-online.target
53+
54+
[Service]
55+
Type=simple
56+
Restart=always
57+
RestartSec=5s
58+
ExecStart=/home/%u/bin/dockerd-rootless.sh
59+
60+
[Install]
61+
WantedBy=default.target
62+
EOL
63+
64+
# Reload systemd user instance, enable and start the service
65+
systemctl --user daemon-reload
66+
systemctl --user enable docker-rootless
67+
systemctl --user start docker-rootless
68+
69+
# Ensure user-level systemd services start at boot
70+
sudo loginctl enable-linger $(whoami)
71+
72+
echo "Docker in rootless mode has been installed and set to start on boot."
73+
74+
sudo yum install libicu -y
75+
echo "Installed libicu Dotnet for the github agent"

0 commit comments

Comments
 (0)