Skip to content

Commit

Permalink
Verified SSH credentials plugin by test and example
Browse files Browse the repository at this point in the history
Fixes #13
  • Loading branch information
MadsNielsen committed Feb 14, 2018
1 parent 60c4063 commit 3a3f3c9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
42 changes: 42 additions & 0 deletions demos/credentials/README.md
Expand Up @@ -44,3 +44,45 @@ we consider the `Impl` suffix as a common pattern to flag implementation class.
=> symbol name is `usernamePassword`


## Examples

A list of some of the more common credentials.

### SSH Credentials

Example that uses the [SSH credentials plugin](https://plugins.jenkins.io/ssh-credentials)

```yaml
credentials:
system:
? name: "test.com"
description: "test.com domain"
specifications:
- hostnameSpecification:
includes:
- "*.test.com"
: - usernamePassword:
scope: SYSTEM
id: sudo_password
username: root
password: ${SUDO_PASSWORD}
? # "global"
- basicSSHUserPrivateKey:
scope: SYSTEM
id: ssh_with_passprase
username: ssh_root
passphrase: ${SSH_KEY_PASSWORD}
description: "SSH passphrase with private key file"
privateKeySource:
fileOnMaster:
keyStoreFile: /docker/secret/id_rsa_2
- basicSSHUserPrivateKey:
scope: SYSTEM
id: ssh_with_passprase_provided
username: ssh_root
passphrase: ${SSH_KEY_PASSWORD}
description: "SSH passphrase with private key file. Private key provided"
privateKeySource:
directEntry:
privateKey: ${SSH_PRIVATE_KEY}
```
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.casc;

import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.CertificateCredentials;
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials;
Expand All @@ -26,6 +27,7 @@ public class SystemCredentialsTest {
public void configure_system_credentials() throws Exception {
System.setProperty("SUDO_PASSWORD", "1234");
System.setProperty("SSH_KEY_PASSWORD", "ABCD");
System.setProperty("SSH_PRIVATE_KEY", "s3cr3t");

ConfigurationAsCode.configure(getClass().getResourceAsStream("SystemCredentialsTest.yml"));

Expand All @@ -39,5 +41,11 @@ public void configure_system_credentials() throws Exception {
final CertificateCredentials cert = certs.get(0);
assertEquals("ABCD", cert.getPassword().getPlainText());

List<BasicSSHUserPrivateKey> sshPrivateKeys = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class, j.jenkins, ACL.SYSTEM, Collections.EMPTY_LIST);
assertEquals(2, sshPrivateKeys.size());
final BasicSSHUserPrivateKey sshUserPrivateKey = sshPrivateKeys.get(0);
assertEquals("ABCD", sshUserPrivateKey.getPassphrase().getPlainText());


}
}
Expand Up @@ -19,4 +19,26 @@ credentials:
keyStoreSource:
fileOnMaster:
keyStoreFile: /docker/secret/id_rsa
- basicSSHUserPrivateKey:
scope: SYSTEM
id: ssh_with_passprase
username: ssh_root
passphrase: ${SSH_KEY_PASSWORD}
description: "SSH passphrase with private key file"
privateKeySource:
fileOnMaster:
keyStoreFile: /docker/secret/id_rsa_2
- basicSSHUserPrivateKey:
scope: SYSTEM
id: ssh_with_passprase_provided
username: ssh_root
passphrase: ${SSH_KEY_PASSWORD}
description: "SSH passphrase with private key file. Private key provided"
privateKeySource:
directEntry:
privateKey: ${SSH_PRIVATE_KEY}





0 comments on commit 3a3f3c9

Please sign in to comment.