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

[WFCORE-5679] Generate and export operation #5075

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lvydra
Copy link
Contributor

@lvydra lvydra commented Apr 25, 2022

@github-actions github-actions bot added the deps-ok Dependencies have been checked, and there are no significant changes label Apr 25, 2022
@yersan yersan requested a review from fjuma April 25, 2022 13:42
@fjuma
Copy link
Contributor

fjuma commented Apr 25, 2022

@darranl Just wanted to check with you since you had created WFCORE-5679 - this issue is about introducing new runtime operations for the credential-store resource. Although it doesn't affect subsystem configuration itself, it does affect documentation. Should we create an RFE to track this?

@darranl
Copy link
Contributor

darranl commented Apr 27, 2022

I think lets get all the pieces together for this first and reassess if we want an RFE. IMO this probably could be an enhancement rather than a full feature.

We should double check we have sufficient tests and we will also need a PR to WildFly for the community documentation.

@@ -90,10 +100,53 @@ abstract class AbstractCredentialStoreResourceDefinition extends SimpleResourceD
.setMinSize(1)
.build();

static final SimpleAttributeDefinition SIZE = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.SIZE, ModelType.STRING, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be ModelType.INT and then setMinSize should be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since all of these attributes are runtime only, I think you can use setStorageRuntime.

static final SimpleAttributeDefinition KEY = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.KEY, ModelType.STRING, false)
.setMinSize(1)
.build();

static final SimpleAttributeDefinition PUBLIC_KEY_STRING = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.PUBLIC_KEY_STRING, ModelType.STRING, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be a public key provided in PEM format, right? If so, I think we could just use public-key instead of public-key-string. I think this is the approach taken elsewhere in the Elytron subsystem.

.setMinSize(1)
.build();

static final SimpleAttributeDefinition PRIVATE_KEY_STRING = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.PRIVATE_KEY_STRING, ModelType.STRING, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

if (algorithmModel.isDefined()) {
algorithm = algorithmModel.asString();
} else {
algorithm = RSA_ALGORITHM;
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value can be defined above using the SimpleAttributeDefinitionBuilder instead of doing it here.

if (sizeModel.isDefined()) {
size = sizeModel.asInt();
} else {
size = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

.setMinSize(1)
.build();

static final SimpleAttributeDefinition PUBLIC_KEY_LOCATION = new SimpleAttributeDefinitionBuilder(ElytronDescriptionConstants.PUBLIC_KEY_LOCATION, ModelType.STRING, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since either PUBLIC_KEY or PUBLIC_KEY_LOCATION should be specified, we should use setAlternatives to specify this. For some examples, there are other places in the Elytron subsystem where setAlternatives is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you checked to verify that an error occurs if neither are specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since either PUBLIC_KEY or PUBLIC_KEY_LOCATION should be specified, we should use setAlternatives to specify this. For some examples, there are other places in the Elytron subsystem where setAlternatives is used.

I have added setAlternatives, however, it's not working here how it is supposed to. I'm not sure if I'm not missing something.

ModelNode privateKeyLocation = PRIVATE_KEY_LOCATION.resolveModelAttribute(context, operation);
ModelNode publicKeyLocation = PUBLIC_KEY_LOCATION.resolveModelAttribute(context, operation);

String passphrase = PASSPHRASE.resolveModelAttribute(context, operation).asString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the PASSPHRASE is optional so it could be null here. Should it be required?

Copy link
Contributor

Choose a reason for hiding this comment

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

In general, would be good to double check which attributes are required for each operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the PASSPHRASE is optional so it could be null here. Should it be required?

Passphrase can be null if none was used to encrypt the key, while it is not recommended. I have added a test case to check it.


import static org.wildfly.extension.elytron._private.ElytronSubsystemMessages.ROOT_LOGGER;

public class KeyPairUtil {
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 need to be public?

public static KeyPair parseKeyPair(String privateKeyContent, String publicKeyContent, ElytronFilePasswordProvider passwordProvider) {
KeyPair keyPair;
try {
keyPair = Pem.parsePemOpenSSHContent(CodePointIterator.ofString(privateKeyContent), passwordProvider).next().tryCast(KeyPair.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to consider having a different parameter for specifying OpenSSH format so we don't try to guess the format. As an example, take a look at how this was done here:

https://github.com/wildfly-security/wildfly-elytron/blob/1.x/auth/client/src/main/resources/schema/elytron-client-1_7.xsd

@fjuma
Copy link
Contributor

fjuma commented Apr 27, 2022

@lvydra Thanks for working on this! I've added some comments. Feel free to let me know if you have any questions.

@lvydra
Copy link
Contributor Author

lvydra commented May 4, 2022

Hi @fjuma Thanks for the review, I have updated PR and added some comments.

@wildfly-ci
Copy link

Core - Full Integration Build 11408 outcome was FAILURE using a merge of 2028ab3
Summary: Tests failed: 1 (1 new), passed: 3989, ignored: 41 Build time: 01:54:07

Failed tests

org.jboss.as.test.integration.messaging.jms.external.prefix.ExternalJMSDestinationDefinitionMessagingDeploymentTestCase.testSendMessage: java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: HTTP Status 500 Response: <html><head><title>ERROR</title><style>
body {
    font-family: "Lucida Grande", "Lucida Sans Unicode", "Trebuchet MS", Helvetica, Arial, Verdana, sans-serif;
    margin: 5px;
}

.header {
    background-image: linear-gradient(bottom, rgb(153,151,153) 8%, rgb(199,199,199) 54%);
    background-image: -o-linear-gradient(bottom, rgb(153,151,153) 8%, rgb(199,199,199) 54%);
    background-image: -moz-linear-gradient(bottom, rgb(153,151,153) 8%, rgb(199,199,199) 54%);
    background-image: -webkit-linear-gradient(bottom, rgb(153,151,153) 8%, rgb(199,199,199) 54%);
    background-image: -ms-linear-gradient(bottom, rgb(153,151,153) 8%, rgb(199,199,199) 54%);
    
    background-image: -webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.08, rgb(153,151,153)),
        color-stop(0.54, rgb(199,199,199))
    );
    color: black;
    padding: 2px;
    font-weight: normal;
    border: solid 1px;
    font-size: 170%;
    text-align: left;
    vertical-align: middle; 
    height: 32px; 
    margin-bottom: 10px;
}
.error-div {
    display: inline-block;
    width: 32px;
    height: 32px;
    background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAgAAAAIACH+pydAAAGGElEQVRYw8WXW2wcVxnHf+fM7NXrdXbdtZ3ipGqCEzvQKmlFoUggwkvvGBoaqVVV5Y0nkCoQPPCAhMQbQlzUh/IWHoh6QUVKZVLxUCGogKZRW9uJkyg0iVzZ2dhre9c7u7M7c87hYWc2M7t2bBASI306O/85+v7/7zLn24H/8yV2u/EcFNvwVNK2X0DKw1qpYaX1gCWlY0m5arRe8JQ6I2DmaVj/nwk4CxO2Zf1aw9dKo6N67+eOZHN7x0gViiSHBmlXa7hrazjLt1i+eKmxUi5bwpg/e8a8PA3X/msBr0MyJ+WvgFOffehY8v7HH5OW78HqGjgOtNrge2AnIJWAgQEYLqBsm3/NvKM/mZ1rYczpRa2/9x3w/iMBM1BCiHfuGRmZevClF9NJ5cP1m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icmFyebzIrdYAAAAASUVORK5CYII=') left center no-repeat;
}
.error-text-div {
    display: inline-block;
    vertical-align: top;
    height: 32px;
}
.label {
    font-weight:bold;
    display: inline-block;
}
.value {
    display: inline-block;
    margin-left: 5px;
}
pre {
    font-size: 110%;


@yersan
Copy link
Collaborator

yersan commented May 27, 2022

hi @lvydra, it looks like errors are related to your changes. Could you take a look?

@yersan yersan added Feature This PR adds a new feature to WildFly missing-reqs This PR is missing external requirements before it can be merged labels May 27, 2022
@lvydra
Copy link
Contributor Author

lvydra commented May 27, 2022

Hi @yersan, thanks, I will look at it.

@@ -221,13 +222,14 @@ public void testExportPublicKey() {
Assert.assertTrue(publicKey.contains("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQ"));
}

@Ignore
Copy link
Contributor

Choose a reason for hiding this comment

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

@lvydra Feel free to let us know when this is ready for another review. Since this test is currently being ignored, it looks like you're working on fixing the test failures, 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.

Hi @fjuma, yes, I'm working on fixing test failures. Ignored tests are written to test setAlternatives behavior, which is currently not working as it's supposed to, so I'm looking for a way how to fix that.

@lvydra lvydra force-pushed the WFCORE-5679 branch 2 times, most recently from fbc1ca2 to 90e2dcf Compare June 21, 2022 13:44
@lvydra
Copy link
Contributor Author

lvydra commented Jun 23, 2022

Hi @fjuma, I think that the PR should be ready for another round of review :-) All requests should be addressed, the only persisting problem is setAlternatives validation, which I haven't been able to get working. I have added a custom validation method using alternatives attribute, however, I don't think it's a suitable solution.

throw ROOT_LOGGER.credentialAlreadyExists(alias, KeyPairCredential.class.getName());
}

ModelNode privateKeyString = PRIVATE_KEY.resolveModelAttribute(context, operation);
Copy link
Contributor

Choose a reason for hiding this comment

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

For optional attributes like this, you could use String privateKey = PRIVATE_KEY.resolveModelAttribute(context, operation).asStringOrNull() so you won't need the isDefined() checks and asString() calls below.

}

@Test
public void testExportPublicKey() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would also be good to add a test for the case where the alias doesn't exist.

@fjuma
Copy link
Contributor

fjuma commented Jun 27, 2022

Thanks for the updates, @lvydra! I've added some comments.

@fjuma
Copy link
Contributor

fjuma commented Jun 27, 2022

What is the issue you're running into with setAlternatives? Is it that it's not actually taking an effect? I wonder if it's because these attributes are only being used for runtime operations.

@lvydra
Copy link
Contributor Author

lvydra commented Jun 28, 2022

Hi @fjuma, thanks for the review, I have updated PR.
Yes exactly, it doesn't take any effect.

@github-actions
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Aug 13, 2022
@fjuma
Copy link
Contributor

fjuma commented Aug 15, 2022

This PR is still active.

@lvydra Looks like there's a conflict that now needs to be resolved.

@wildfly-ci
Copy link

Hello, lvydra. I'm waiting for one of the admins to verify this patch with /ok-to-test in a comment.

@lvydra
Copy link
Contributor Author

lvydra commented Aug 16, 2022

Hi @fjuma, thanks, resolved.

@yersan
Copy link
Collaborator

yersan commented Sep 23, 2022

@fjuma / @darranl Is there any decision about handling this as an enhancement vs Feature Request?
Since there is a user controllable action here, probably it is more inclined to a Feature Request, however, it seems it doesn't change the subsystem configuration, so here are my doubts.

@fjuma
Copy link
Contributor

fjuma commented Oct 3, 2022

@lvydra Thanks for the updates! Sorry for the delayed response, just catching up after being away for a couple weeks.

Just to check, have you already created a PR against WildFly with the corresponding community documentation?

@lvydra
Copy link
Contributor Author

lvydra commented Oct 4, 2022

Hi @fjuma, not yet, I will prepare a documentation update and open PR.

@lvydra
Copy link
Contributor Author

lvydra commented Oct 6, 2022

Hi @fjuma, I have opened documentation PR: wildfly/wildfly#16139

@github-actions
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Nov 21, 2022
@fjuma
Copy link
Contributor

fjuma commented Nov 21, 2022

This PR is still active.

@github-actions github-actions bot removed the Stale label Nov 22, 2022
@github-actions
Copy link

github-actions bot commented Jan 7, 2023

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Jan 7, 2023
@fjuma
Copy link
Contributor

fjuma commented Jan 9, 2023

This PR is still active.

@github-actions github-actions bot removed the Stale label Jan 10, 2023
@github-actions
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Feb 25, 2023
@github-actions
Copy link

There has been no activity on this PR for 90 days and it has been closed automatically.

@github-actions github-actions bot closed this May 27, 2023
@lvydra lvydra reopened this Jun 26, 2023
@github-actions
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Aug 12, 2023
@fjuma
Copy link
Contributor

fjuma commented Aug 14, 2023

This PR is still active

@github-actions github-actions bot removed the Stale label Aug 15, 2023
@github-actions
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Sep 29, 2023
Copy link

There has been no activity on this PR for 90 days and it has been closed automatically.

@github-actions github-actions bot closed this Dec 28, 2023
@lvydra lvydra reopened this Jan 31, 2024
@github-actions github-actions bot removed the Stale label Feb 1, 2024
Copy link

There has been no activity on this PR for 45 days. It will be auto-closed after 90 days.

@github-actions github-actions bot added the Stale label Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deps-ok Dependencies have been checked, and there are no significant changes Feature This PR adds a new feature to WildFly missing-reqs This PR is missing external requirements before it can be merged Stale
Projects
None yet
5 participants