Skip to content

Check Prop Value Format and Key types.#3146

Closed
ddanielr wants to merge 2 commits into
apache:2.1from
ddanielr:bugfix/check-property-values
Closed

Check Prop Value Format and Key types.#3146
ddanielr wants to merge 2 commits into
apache:2.1from
ddanielr:bugfix/check-property-values

Conversation

@ddanielr
Copy link
Copy Markdown
Contributor

relates to #3145

The shell config command was only checking Property Key Types and not Value Formats on Set operations. Changed Set operation to also validate value types to ensure proper format before setting properties.

This changes the shell client behavior to now throw an error message to the user on an invalid property setting.

Boolean Example:

root@uno> config -s tserver.port.search=123
2022-12-30T15:14:21,363 [shell.Shell] ERROR: org.apache.accumulo.core.util.BadArgumentException: Invalid Property value (requires type: boolean) near index 30
config -s tserver.port.search=123

Port Example:

root@uno> config -s tserver.port.client=65539
2022-12-30T15:15:29,328 [shell.Shell] ERROR: org.apache.accumulo.core.util.BadArgumentException: Invalid Property value (requires type: port) near index 30
config -s tserver.port.client=65539

This PR is staged against main, but we may want to backport this change.

Comment thread shell/src/main/java/org/apache/accumulo/shell/commands/ConfigCommand.java Outdated
Comment thread shell/src/main/java/org/apache/accumulo/shell/commands/ConfigCommand.java Outdated
@ctubbsii ctubbsii linked an issue Dec 30, 2022 that may be closed by this pull request
Copy link
Copy Markdown
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

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

Ideally we'd validate property values on the server side, and reject the RPC request (and propagate the error through the public API call), when validation fails.

@ctubbsii
Copy link
Copy Markdown
Member

I think the fix, when ready, can be applied to the 2.1 branch. This PR is currently targeting the main branch. If you cherry-pick the changes to a 2.1 bugfix branch, and force push to the branch that is backing this PR, we can edit the PR's base branch to make this a PR against 2.1.

@keith-turner
Copy link
Copy Markdown
Contributor

If possible, it would be nice to add an IT to the ShellIT that exercises setting a prop w/ a bad value.

@keith-turner
Copy link
Copy Markdown
Contributor

Ideally we'd validate property values on the server side, and reject the RPC request (and propagate the error through the public API call), when validation fails.

Is there a bigger problem here? Re my comment earlier about testing the shell, it might be nice to have an IT for the public API also that tries to set a bad value if we do not have one.

@ddanielr
Copy link
Copy Markdown
Contributor Author

Ideally we'd validate property values on the server side, and reject the RPC request (and propagate the error through the public API call), when validation fails.

Yep, I'm working on that now. I think it's also valuable to have the shell perform validation and not issue the RPC request in the first place.

}

private void validatePropertyType(String property, String value, String fullCommand,
String tableName) throws BadArgumentException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like instead of tableName the parameter is more generic name (either table name of namespace name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how to determine the best fix for this since namespace and table don't have good property separation.

Only ValidTableProperties are defined in Property.java.
There is not a separate ValidNamespaceProperties hashset defined.

private static final HashSet<String> validTableProperties = new HashSet<>();
private static final HashSet<String> validProperties = new HashSet<>();
private static final HashSet<String> validPrefixes = new HashSet<>();
private static final HashMap<String,Property> propertiesByKey = new HashMap<>();

You can also see the interchangeability in the property set code for namespace. It's just checking if it's a valid table property vs anything namespace specific.

} else if (namespace != null) {
if (!Property.isValidTablePropertyKey(property)) {

So, should namespaces have separate properties that aren't table properties?
if so, I can rework this and also add a isValidNamespacePropertyKey method to Property.java

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Properties are a hierarchy default <- system <- namespace <- table with the more specific overriding the more generic. I'm not sure of the top of my head, but I expect that all table properties are valid namespace properties. There may be a few specific system only props, but in general they should also be override-able in a namespace or table.

The shell config command was only checking Property Key Types and not Value Formats on Set operations.
Changed Set operation to also validate value types to ensure proper format before setting properties.
Added IT test for checking property types using shell commands.
Refactored ConfigCommand.java to reduce code duplication.
@ddanielr ddanielr force-pushed the bugfix/check-property-values branch from 339672a to 8ecfdc5 Compare January 27, 2023 08:42
@ddanielr ddanielr changed the base branch from main to 2.1 January 27, 2023 08:43
@ddanielr
Copy link
Copy Markdown
Contributor Author

I've thought about these changes and I'm closing this PR in favor of the fix in #3177

@ddanielr ddanielr closed this Jan 31, 2023
@ddanielr ddanielr deleted the bugfix/check-property-values branch January 31, 2023 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell commands allow for invalid Property types to be set

5 participants