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

Add ansible config for dev desktops #79

Merged
merged 61 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
245ba25
Add ansible config for dev desktops
oli-obk Oct 14, 2021
66ec265
inline the repository instead of checking it out
oli-obk Oct 14, 2021
ffe4206
Delete keys of nonexistant users
oli-obk Nov 16, 2021
963280b
Run rustfmt
oli-obk Nov 16, 2021
32922a4
Minimize dependencies
Mark-Simulacrum Dec 9, 2021
c42a8b1
Fix ansible configuration
Mark-Simulacrum Dec 9, 2021
e3344a8
Preinstall commonly used tooling
Mark-Simulacrum Dec 9, 2021
e9af82d
lld from ubuntu is too old for rustc
Mark-Simulacrum Dec 9, 2021
337e984
Don't install cargo/rust globally, it will conflict with users' rustup
oli-obk Dec 10, 2021
c45de29
Update main.yml
oli-obk Dec 16, 2021
8a16c5b
Update ansible/roles/dev-desktop/tasks/main.yml
oli-obk Jan 12, 2022
6a073ab
Remove accidentally added script
oli-obk Mar 10, 2022
e1eeeda
Preemptively allow users to cross compile
oli-obk Mar 10, 2022
85951d9
Add message of the day
oli-obk Mar 14, 2022
7fa279f
Add actual URL to motd
oli-obk Mar 16, 2022
6cbccc2
Add terraform configuration
Mark-Simulacrum Mar 16, 2022
8c8b50a
Launch a new bash to get the rustup PATH changes loaded in
oli-obk Mar 16, 2022
378f042
Manually tweak the PATH to pick up cargo and rustc
oli-obk Mar 16, 2022
b36cf97
Make sure linkers and c compilers are installed
oli-obk Mar 16, 2022
71e973c
Retry crontab replacement
oli-obk Mar 17, 2022
627162f
Attempt to make the user permission reset conditional and disable it …
oli-obk Mar 17, 2022
c050cd2
Fix ansible syntax
Mark-Simulacrum Mar 17, 2022
1d9f3cc
Update stackoverflow snippet to latest ansible version
oli-obk Mar 17, 2022
18b2c5b
Make motd executable
oli-obk Mar 17, 2022
98790d2
Try to replace the entire motd
oli-obk Mar 17, 2022
e0fd436
Just overwrite the entire motd
oli-obk Mar 17, 2022
6c3d0d6
Don't use `skel`, instead install the scripts globally
oli-obk Mar 22, 2022
e2712ea
Silence the monitoring infra alert about motd
oli-obk Mar 22, 2022
ef8cef6
Prefix all usernames with `gh-`
oli-obk Mar 22, 2022
881420f
Check whether the specific user is even allowed on the dev desktop
oli-obk Mar 22, 2022
5011997
Switch to using the new dev desktop team data
oli-obk Apr 4, 2022
7ff0358
Use a custom user agent so that we see who is doing all those accesse…
oli-obk Apr 4, 2022
9fe782b
Re-add the skel just for the default config.toml
oli-obk Apr 4, 2022
d4546d1
Grab the github username by stripping the `gh-` prefix
oli-obk Apr 4, 2022
e276a0c
Add a script to generate new access tokens for repos where the github…
oli-obk Apr 4, 2022
52793ac
Update ansible/roles/dev-desktop/templates/motd_rules
oli-obk Apr 9, 2022
431c443
Avoid fetching gh-X as authorized user
Mark-Simulacrum Apr 21, 2022
2e3eee3
Update ansible/roles/dev-desktop/files/skel/config.toml
oli-obk Apr 23, 2022
34f7a7b
ansible has pip magic, too
oli-obk Apr 4, 2022
6e5ef9b
Set the users' default shell to bash
oli-obk Apr 25, 2022
0ab6969
Fix the init script to work without login capabilities
oli-obk Apr 25, 2022
7d07c2d
Make init script executable by everyone
oli-obk Apr 25, 2022
b63a614
Make all scripts executable by everyone
oli-obk Apr 25, 2022
427776f
Remove the autogenerated ubuntu header
oli-obk Apr 25, 2022
96c8fc5
Add explainer for all the scripts
oli-obk Apr 25, 2022
baa8ffa
Make help script bash-friendly
oli-obk Apr 25, 2022
a211d7d
Use ansible to delete files instead of shelling out to `rm`
oli-obk Apr 26, 2022
b70547b
Disable motd-news service
oli-obk Apr 26, 2022
0d751d1
Also stop the timer via ansible
oli-obk Apr 27, 2022
2f4974d
Fix scripts
oli-obk Apr 27, 2022
0a5f1b7
Automatically register the worktrees with rustup
oli-obk Apr 27, 2022
72c0e08
Add some basic instructions for Github App setup
oli-obk Apr 29, 2022
0033849
All your instructions are belong to server
oli-obk May 2, 2022
70170e2
Reorder steps
oli-obk May 2, 2022
f78c741
Create git credential helper
oli-obk May 2, 2022
ebfa0db
Make the git credential helper available globally
oli-obk May 2, 2022
b355200
Add a seperate ssh group for dev-desktop users
oli-obk May 2, 2022
f0df09e
Only add the dev-desktop-allow-ssh group on the dev-desktop
oli-obk May 9, 2022
03573ed
Add worflows permission to instructions
oli-obk May 9, 2022
2364c06
Load the correct user when using the app
oli-obk May 9, 2022
0cc3e3c
Move docs to forge
oli-obk May 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ansible/envs/prod/hosts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ ci-arm-1.infra.rust-lang.org

[playground]
play-1.infra.rust-lang.org

[dev-desktop]
dev-desktop.infra.rust-lang.org
18 changes: 18 additions & 0 deletions ansible/playbooks/dev-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---

- hosts: dev-desktop
become: yes
become_user: root

roles:

- role: common
papertrail_url: "{{ vars_papertrail_url }}"
collect_metrics_from: "{{ global_collect_metrics_from }}"
sudo_users:
- aidanhs
- simulacrum
- pietro
- oli-obk

- role: dev-desktop
1 change: 1 addition & 0 deletions ansible/roles/common/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ sudo_users: []
collect_metrics_from: []
avoid_removing_docker_users: []
papertrail_url: null
allow_ssh_extra_groups: ""
8 changes: 8 additions & 0 deletions ansible/roles/common/files/ssh-keys/oli-obk.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDIU/eDOjiDgwwXrsKTqUW3/N8DWCgYedNOXF1ZhI5wybi13kX7TMehEDN/tVYVe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kE9L5a862rC8ws0LZPvH+UDE1AIeIDjIpk7Nc+yZ9OhwfgCMcmSqGvuEGLWWyrGkgvW6Gs8OHyvcTRve3AOQz3MG3ZynPjvA1PwVD3ktedsxLnhBGyGBrStS3wCZjFrfgfmYEFBXeZKK9Y/vwcaHizd9ueQTT04Pd0=
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC72WFM7SMdUL7IRfLzWfFrKWj/S9Ri84LXSj80EnZy2iM2EISn2ZWUXhNRf+sKCRg1gLji9gdqojo5jB+e8/4O5lBG88y0lVtLi7HvVMK9QjzAlr7mU6o0iEjpeS1VFcTKjI8nxBpJQ1+URr31V52VzZ1yx2Rd2DxLoL2/+smFb3JwGJaAviPgL2BLjz444obX5rWNViFIp7OICLRWWXBxNdPrq7Ayiwubl3WA59PenjytKldaRY8eGLmDjAJvUM/xWcq0Fnep/+g5y7tou3MXO9a9+8EmcApB8OY7+dYNH8LSU26Erd6kx/qZgPD7omqTq3eNHavbW5HaWXhCwbJ38dqWgkocKWWVUjBHwdd5V5/tYIFuqam49QOyGKoJ2hDVt6xwDGYcUPIG3qAi6VfMGTF1C71BKq6aCRuthxs8owy4/LMea+O6XyLBJXUSk0DX7orPzamgVzbzfpEVGqdHb/gGqk2BmG86aWrmkV9vuIvDAJMpsI5ajdTaSYiCOXE=
2 changes: 1 addition & 1 deletion ansible/roles/common/templates/ssh/sshd_config
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

AllowGroups allow-ssh
AllowGroups allow-ssh {{ allow_ssh_extra_groups }}

{# The `Include` directive is not supported on older Ubuntu versions #}
{% if ansible_distribution_release not in ["xenial", "bionic"] %}
Expand Down
4 changes: 4 additions & 0 deletions ansible/roles/dev-desktop/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

vars_team_login_path: "/root/team_login"
allow_ssh_extra_groups: "dev-desktop-allow-ssh"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import os

from github import Github
from pprint import pprint

from sys import argv

from datetime import datetime, timedelta, timezone

from github import GithubIntegration

real_path = os.path.realpath(__file__)
dir_path = os.path.dirname(real_path)


def token(user, repo):
with open(os.path.join(dir_path, 'app_id.txt'), 'r') as fh:
app_id = int(fh.read())

with open(os.path.join(dir_path, 'dev-desktop.private-key.pem'), 'rb') as fh:
private_key = fh.read()

integration = GithubIntegration(app_id, private_key)

installation = integration.get_installation(user, repo)

auth = integration.get_access_token(installation.id)

return auth.token


if __name__ == '__main__':
# executed as script, fetch args and dump result on command line

if len(argv) < 2:
print("usage: <github_username> <github_repo_name>")

print(token(argv[1], argv[2]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/python

from sys import argv, stdin
import os

if argv[1] != "get":
exit(0)

config = [x.strip() for x in stdin]

if config[1] != "host=github.com":
exit(0)

path = config[2].split('=')
path = path[1].split('/')

# Get the username of the caller, not the owner of
# this script (which is setuid)
user = os.getlogin()
if user.starts_with("gh-"):
user = user[3:]

# we don't support usernames differing from repo owner names for now
if user != path[0]:
exit(0)
repo = path[1].rsplit('.', 1)[0]

real_path = os.path.realpath(__file__)
dir_path = os.path.dirname(real_path)

from dump import token

for config in config:
print(config)

print(f"username={user}")

print(f"password={token(user, repo)}")
print()

3 changes: 3 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

rm -rf rust*/build
10 changes: 10 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/detach_merged_prs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

for d in rust*
do
cd $d
echo $d
# if the fast forward is successful, this branch is merged, so we can kill it
git pull upstream master --ff-only && git checkout --detach && git submodule update --init --recursive
cd ..
done
11 changes: 11 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/help.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

echo "# Available scripts for managing your Rust checkouts"
echo "init.sh | first time setup, you should only have to execute this once on a new machine"
echo "status.sh | list the branches and git status of all copies of the Rust repo"
echo "new_worktree.sh | creates a worktree (shallow copy of the main git checkout of Rust, sharing the .git folder)"
echo "detach_merged_prs.sh | invokes \"git pull --fast-forward-only\" on all worktrees and detaches those that are equal to the \"master\" branch"
echo ""
echo "# Rarer commands:"
echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken"

14 changes: 14 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

username=`id -u -n`
gh_name=${username#"gh-"}

# Using https instead of git urls because vscode only handles login on push/pull
git clone https://github.com/$gh_name/rust.git
pushd rust
git remote add upstream https://github.com/rust-lang/rust.git
git fetch upstream
git checkout upstream/master
popd

./setup_rustup.sh
16 changes: 16 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/new_worktree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -ex

N=$(ls | grep -E -e "rust[0-9]+" | wc -l)
echo $N
pushd rust
git worktree add --detach ../rust$N
popd
pushd rust$N
git fetch upstream
git checkout upstream/master
ln -s ../config.toml
popd

./setup_rustup.sh
9 changes: 9 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/set_defaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

for D in rust*; do
if [ -d "${D}" ]; then
pushd $D
ln -s ../config.toml
popd
fi
done
12 changes: 12 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/setup_rustup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -x

rustup --version || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

for D in rust*; do
if [ -d "${D}" ]; then
rustup toolchain link "$D"_stage1 "$D/build/x86_64-unknown-linux-gnu/stage1"
rustup toolchain link "$D"_stage2 "$D/build/x86_64-unknown-linux-gnu/stage2"
fi
done
9 changes: 9 additions & 0 deletions ansible/roles/dev-desktop/files/scripts/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

for d in rust*
do
cd $d
echo $d
git status --short --branch --untracked-files=no --ignore-submodules --no-ahead-behind --no-renames
cd ..
done
9 changes: 9 additions & 0 deletions ansible/roles/dev-desktop/files/skel/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
changelog-seen = 2

# Change this to the profile of your choice
profile = "compiler"

[rust]
# Build with debug assertions so we get useful RUSTC_LOG
# and notice debug assertions failing.
debug = true
1 change: 1 addition & 0 deletions ansible/roles/dev-desktop/files/team_login/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Loading