~comcloudway/builds.sr.ht

7c4a938c8fd8a4639784bd1a2a577e9328f3eaec — Tharre 5 years ago 0bf74bf
Correctly handle newlines in SSH keys

OpenSSH does not like carriage returns in it's key files and will reject
the key:

> Load key "/home/build/.ssh/id_ed25519": invalid format

Fixes #189.
1 files changed, 5 insertions(+), 3 deletions(-)

M buildsrht/blueprints/secrets.py
M buildsrht/blueprints/secrets.py => buildsrht/blueprints/secrets.py +5 -3
@@ 42,14 42,16 @@ def secrets_POST():
        for f in ["secret", "file-file"]:
            valid.expect(bool(_secret) ^ bool(secret_file),
                    "Either secret text or file have to be provided", field=f)
    else:
        _secret = valid.require("secret", friendly_name="Secret")

    if secret_type in (SecretType.plaintext_file, SecretType.ssh_key):
        if _secret:
            _secret = _secret.replace('\r\n', '\n')
            if not _secret.endswith('\n'):
                _secret += '\n'
        else:
        elif secret_type == SecretType.plaintext_file:
            _secret = secret_file
    else:
        _secret = valid.require("secret", friendly_name="Secret")

    if isinstance(_secret, str):
        _secret = _secret.encode()