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

Delete UNIQUE constraint on subject_dn column of iam_x509_cert table #672

Merged
merged 8 commits into from
Dec 11, 2023

Conversation

rmiccoli
Copy link
Contributor

@rmiccoli rmiccoli commented Nov 23, 2023

This is a fix for the already closed issue #550
There's still a UNIQUE constraints on subject_dn column of iam_x509_cert table which has to be removed.
Also the search logic has to be fixed from finding a certificate through the subject to finding a certificate through both subject and issuer.

of iam_x509_cert because it causes certificate
duplication error with same dn but different issuer
considering subjectDn AND issuerDn
that guarantee uniqueness
Copy link
Member

@enricovianello enricovianello left a comment

Choose a reason for hiding this comment

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

I added some comments/questions

@@ -44,7 +44,7 @@ public class FindAccountController {
public static final String FIND_BY_LABEL_RESOURCE = "/iam/account/find/bylabel";
public static final String FIND_BY_EMAIL_RESOURCE = "/iam/account/find/byemail";
public static final String FIND_BY_USERNAME_RESOURCE = "/iam/account/find/byusername";
public static final String FIND_BY_CERT_SUBJECT_RESOURCE = "/iam/account/find/bycertsubject";
public static final String FIND_BY_CERT_SUBJECT_AND_ISSUER_RESOURCE = "/iam/account/find/bycertsubjectandissuer";
Copy link
Member

Choose a reason for hiding this comment

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

Does this brake the UI? Surely a documentation fix is necessary here https://indigo-iam.github.io/v/v1.8.3/docs/reference/api/account-api/#account-filtering

Copy link
Contributor Author

@rmiccoli rmiccoli Dec 1, 2023

Choose a reason for hiding this comment

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

I don't think so, simply change the logic and two query parameters for the search, subjectDn and issuerDn are needed (URL-encoded). E.g.

http://localhost:8080/iam/account/find/bycertsubjectandissuer?certificateSubject=XXX&certificateIssuer=XXX

Obviously, as soon as it is approved, the documentation will also have to be modified accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that we can't search anymore only by cert subject?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because since subjectDn no longer has the uniqueness constraint the search returns two records (in case one account has two certificates with same subject and different issuer) and thus gives an error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, but searching for subject is useful. What's the problem if I get back two (or more) records? who gives the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we would get duplicate records, right? The resulting exception is IncorrectResultSizeDataAccessException and comes from spring framework.
However, if we want to keep the search by subject, we can revise the logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect that most of the times the search will be done using just the cert subject, so that has to work in my opinion. The we can add the possibility to search specifying also the issuer. It wouldn't be bad to search also by serial number and issuer (for example). I wonder if it wouldn't be better to leave /bycertsubject as it is for backwards compatibility (fixing possible bugs, of course) and add a new /bycert, with the new options

Copy link
Contributor

Choose a reason for hiding this comment

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

But... I don't think we keep the serial number, so a search based on it doesn't make much sense, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, that's how it is!

.andExpect(jsonPath("$.Resources[0].userName", is("admin")));

}

Copy link
Member

Choose a reason for hiding this comment

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

I'd add a "notFound" test with fake issuer and right subject, a fake subject and right issuer and both fake items.

This reverts commit 778eeea.
but add DISTINCT statement so that search
by subjectDn does not return duplicates
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@enricovianello enricovianello merged commit 8a10e8e into develop Dec 11, 2023
5 checks passed
@enricovianello enricovianello deleted the delete-unique-subjectdn branch January 23, 2024 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants