-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpmbuild: add tooling for "safer" RH subscription
The daemon part partly a C&P from https://pagure.io/fedora-infra/ansible/blob/8ff1e6d9f79ca86e/f/roles/copr/backend/files/provision/copr-rh-subscribe.sh Closes: #3434 Relates: #3426
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#! /usr/bin/python3 | ||
|
||
""" | ||
Run `subscription-manager register` without having the --activation key in | ||
/proc/self/environ or /proc/self/comm. | ||
""" | ||
|
||
import argparse | ||
import getpass | ||
import sys | ||
|
||
from subscription_manager.scripts.subscription_manager import main as rhsm | ||
|
||
|
||
def read_key(): | ||
""" | ||
Read key from stdin if not a tty. Never export as env-var. | ||
""" | ||
if sys.stdin.isatty(): | ||
key = getpass.getpass("rhsm key: ") | ||
else: | ||
key = sys.stdin.read() | ||
return key.strip() | ||
|
||
|
||
def _arg_parser(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--org-id", required=True) | ||
parser.add_argument("--system-name", required=True) | ||
return parser | ||
|
||
|
||
def _main(): | ||
opts = _arg_parser().parse_args() | ||
a_key = read_key() | ||
sys.argv = [ | ||
"subscription-manager", "register", "--force", | ||
"--org", opts.org_id, | ||
"--name", opts.system_name, | ||
"--activationkey", a_key, | ||
] | ||
# Call subscription-manager's internal method to avoid polluting the | ||
# /proc/self/cmdline with the key credential! | ||
rhsm() | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! /bin/bash | ||
|
||
# Try to run subscription-manager register repeatedly (till it succeeds), | ||
# without polluting environment variables or command-line options with | ||
# passwords/keys. | ||
|
||
if test $# -ne 2; then | ||
cat <<EOHELP >&2 | ||
Usage: $0 ORG_ID SYSTEM_NAME <<<"\$password" | ||
Provide the activation_key on stdin! | ||
EOHELP | ||
exit 1 | ||
fi | ||
|
||
opt_org_id=$1 | ||
opt_system=$2 | ||
|
||
try_indefinitely() | ||
{ | ||
cmd=( "$@" ) | ||
while :; do | ||
if "${cmd[@]}"; then | ||
break | ||
fi | ||
sleep 5 | ||
done | ||
} | ||
|
||
test "$(id -u)" = 0 || { | ||
echo >&2 "run as root" | ||
exit 1 | ||
} | ||
|
||
test -t 0 && echo -n "RH Activation Key: " | ||
read -r -s opt_pass | ||
|
||
register() | ||
{ | ||
copr-builder-rhsm-subscribe --org-id "$opt_org_id" --system-name "$opt_system" <<<"$opt_pass" | ||
} | ||
|
||
try_indefinitely register | ||
touch /run/copr-builder/rhsm-subscribed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters