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

Bugfix: Removed @RequirePost and changed ssh key migration behavior #498

Merged
merged 3 commits into from
Sep 18, 2020
Merged
Changes from 1 commit
Commits
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
12 changes: 5 additions & 7 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,6 @@ protected EC2Cloud(String id, boolean useInstanceProfileForCredentials, String c
this.credentialsId = credentialsId;
this.sshKeysCredentialsId = sshKeysCredentialsId;

if (this.sshKeysCredentialsId == null && ( this.privateKey != null || privateKey != null)){
migratePrivateSshKeyToCredential(this.privateKey != null ? this.privateKey.getPrivateKey() : privateKey);
}
this.privateKey = null; // This enforces it not to be persisted and that CasC will never output privateKey on export


if (templates == null) {
this.templates = Collections.emptyList();
} else {
Expand Down Expand Up @@ -250,6 +244,11 @@ protected Object readResolve() {
for (SlaveTemplate t : templates)
t.parent = this;

if (this.sshKeysCredentialsId == null && this.privateKey != null ){
migratePrivateSshKeyToCredential(this.privateKey.getPrivateKey());
}
this.privateKey = null; // This enforces it not to be persisted and that CasC will never output privateKey on export

if (this.accessId != null && this.secretKey != null && credentialsId == null) {
String secretKeyEncryptedValue = this.secretKey.getEncryptedValue();
// REPLACE this.accessId and this.secretId by a credential
Expand Down Expand Up @@ -1066,7 +1065,6 @@ public ListBoxModel doFillSshKeysCredentialsIdItems(@QueryParameter String sshKe
.includeCurrentValue(sshKeysCredentialsId);
}

@RequirePOST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like fine to remove this annotation here, the method is just returning whether the credential-id showed is an actual rsa private key. But better to confirm with some security person: @daniel-beck, @Wadeck, ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's still a permission check.

The docs for this are at https://www.jenkins.io/doc/developer/security/form-validation/ -- please read and if anything specific is unclear, ask.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSshCredential retrieves credentials, but as the RequirePOST protects against CSRF, there is no issue. The method is already checking for ADMINISTER.

Side note, such methods should not have troubles to use POST for the check. You can change the

<f:entry field="sshKeysCredentialsId" title="${%EC2 Key Pair's Private Key}">
(and similar for Eucalyptus) by adding checkMethod="post"

public FormValidation doCheckSshKeysCredentialsId(@QueryParameter String value) throws IOException, ServletException {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

Expand Down