-
Notifications
You must be signed in to change notification settings - Fork 108
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
[JENKINS-37655] Use Credentials API for SMTP authentication #88
base: master
Are you sure you want to change the base?
[JENKINS-37655] Use Credentials API for SMTP authentication #88
Conversation
Build is currently held up because the Jenkins plugin parent POM artifact does not exist in Jenkins Incrementals.
|
The current design is a backwards-incompatible replacement. It adds That's quite a change so it is worth considering whether backwards compatibility can be retained, and whether this would be advisable:
|
To borrow @Vlatombe 's directions for maintaining backwards compatibility when I did this migration with a closed source plugin: To handle the migration of old data, keep the old fields with Then you'll need to implement
in order to create credentials from prior username/password, then set these to null to do it only once. |
Makes sense. I've got a potential config data migration coming up in a different plugin and have been thinking about how best to test it. Migrations are a fact of life for many plugins so I'm looking for a testing mechanism that would make migrations a first-class citizen of the test suite, making it easy to write migration tests for any plugin, and indeed giving new developers a one-stop shop to see all the migrations currently active in any plugin. (They shouldn't have to go digging for deprecated or transient fields.) I didn't see any such mechanism so far, so I've proposed a Feedback welcomed either below or in jenkinsci/aws-secrets-manager-credentials-provider-plugin#32 |
I'm in the middle of adding the migration code, and have come across a couple of issues:
Advice appreciated |
I've now added migration code that will attempt to create a credential with a random ID from the legacy username and password fields. It specifically tries to save it to the on-disk In the unlikely event that a credential already exists with the generated ID, the migration code retries 10 times (this is arbitrary and can be changed), generating new IDs each time. Ready for another code review |
username, | ||
password.getEncryptedValue()); | ||
|
||
store.addCredentials(Domain.global(), migratedCredential); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ignored the return value, as a failure should be expressed by the method throwing an exception. Is this alright?
@@ -334,7 +347,7 @@ public void testPipelineCompatibility() throws Exception { | |||
public void testMigrateOldData() { | |||
Mailer.DescriptorImpl descriptor = Mailer.descriptor(); | |||
assertTrue("Mailer can not be found", descriptor != null); | |||
assertEquals(String.format("Authentication did not migrate properly. Username expected %s but received %s", "olduser", descriptor.getAuthentication().getUsername()), "olduser", descriptor.getAuthentication().getUsername()); | |||
assertEquals(String.format("Authentication did not migrate properly. Credentials ID expected %s but received %s", CREDENTIALS_ID, descriptor.getAuthentication().getCredentialsId()), CREDENTIALS_ID, descriptor.getAuthentication().getCredentialsId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is needed, since I have dedicated migration tests for it now.
this.username = username; | ||
this.password = password; | ||
readResolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put this here since this legacy constructor should only be called by the migration code in Mailer, and I wanted to avoid constructing credentials in 2 places (Mailer#readResolve
and SMTPAuthentication#readResolve
). Is this alright?
|
||
Optional<Authenticator> authenticator = Optional.ofNullable(credentialsId) | ||
.map(id -> CredentialsMatchers.firstOrNull( | ||
CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, (Item) null, ACL.SYSTEM, Collections.emptyList()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need to do anything extra for credentials tracking here, or does a call to lookupCredentials
append to the tracking log automatically?
@alecharp would you be able to take a look at this? If I can get a resolution to the questions, I can rebase it and get it ready to merge. |
@alecharp please look into this PR. That's a nice feature for us to. We use sendgrid and want to hide the token. We have cloudbees setup ;) |
I'm sorry I haven't looked at this before. This would be a nice addition to the plugin. However, now there are conflicts. @chriskilding could you re-work on this? |
62d3c8d
to
8a12a15
Compare
Hi @alecharp, I've rebased it and caught up with recent changes. The 4 failing tests call Couple of options to fix: The first is to remove The second is to provide backwards compatibility, by calling |
8a12a15
to
bf90736
Compare
@alecharp could you take a look at this? |
bf90736
to
48c9f9a
Compare
Implements JENKINS-37655
To do: