Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
import org.opensearch.security.privileges.PrivilegesEvaluator;
import org.opensearch.security.securityconf.DynamicConfigFactory;
import org.opensearch.security.securityconf.Hideable;
import org.opensearch.security.securityconf.StaticDefinable;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
import org.opensearch.security.ssl.transport.PrincipalExtractor;
Expand Down Expand Up @@ -588,23 +586,13 @@ protected void notImplemented(RestChannel channel, Method method) {
}

protected final boolean isReserved(SecurityDynamicConfiguration<?> configuration, String resourceName) {
if (isStatic(configuration, resourceName)) { // static is also always reserved
return true;
}

final Object o = configuration.getCEntry(resourceName);
return o != null && o instanceof Hideable && ((Hideable) o).isReserved();
return configuration.isStatic(resourceName) || configuration.isReserved(resourceName);
}

protected final boolean isHidden(SecurityDynamicConfiguration<?> configuration, String resourceName) {
return configuration.isHidden(resourceName) && !isSuperAdmin();
}

protected final boolean isStatic(SecurityDynamicConfiguration<?> configuration, String resourceName) {
final Object o = configuration.getCEntry(resourceName);
return o != null && o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
}

/**
* Consume all defined parameters for the request. Before we handle the
* request in subclasses where we actually need the parameter, some global
Expand Down Expand Up @@ -636,7 +624,7 @@ protected boolean isSuperAdmin() {
* @return True if resource readonly
*/
protected boolean isReadOnly(final SecurityDynamicConfiguration<?> existingConfiguration, String name) {
return isSuperAdmin() ? false : isReserved(existingConfiguration, name);
return !isSuperAdmin() && isReserved(existingConfiguration, name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
import com.fasterxml.jackson.databind.JsonNode;

import org.opensearch.ExceptionsHelper;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.security.DefaultObjectMapper;
Expand Down Expand Up @@ -216,11 +213,6 @@ public boolean exists(String key) {
return centries.containsKey(key);
}

@JsonIgnore
public BytesReference toBytesReference() throws IOException {
return XContentHelper.toXContent(this, XContentType.JSON, false);
}

@Override
public String toString() {
return "SecurityDynamicConfiguration [seqNo="
Expand Down Expand Up @@ -322,7 +314,19 @@ public boolean containsAny(SecurityDynamicConfiguration other) {

public boolean isHidden(String resourceName) {
final Object o = centries.get(resourceName);
return o != null && o instanceof Hideable && ((Hideable) o).isHidden();
Copy link
Member

Choose a reason for hiding this comment

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

TIL that a nullcheck is redundant if calling instanceof immediately after because null instanceof SomeClass will always return false.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

return o instanceof Hideable && ((Hideable) o).isHidden();
}

@JsonIgnore
public boolean isStatic(final String resourceName) {
final Object o = centries.get(resourceName);
return o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
}

@JsonIgnore
public boolean isReserved(final String resourceName) {
final Object o = centries.get(resourceName);
return o instanceof Hideable && ((Hideable) o).isReserved();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking into this method of AbstractApiAction::isReserved that says static is also always reserved, should we baked it into the isReserved check?

Copy link
Collaborator Author

@willyborankin willyborankin Jun 26, 2023

Choose a reason for hiding this comment

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

It is the same in the AbstractApiAction class. The PR fixes the broken responsibility since the configuration has a predefined reserved and static fields. E.g. isHidden was moved while isStatic and isReseved not

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, let me try to ask the question this way:

  • why AbstractApiAction::isReserved checks configuration.isStatic(resourceName) || configuration.isReserved(resourceName)
  • but SecurityDynamicConfiguration::isReserved is only checking isReserved ?

May be AbstractApiAction::isReserved should be renamed or SecurityDynamicConfiguration::isReserved should include isStatic check as well?

Copy link
Collaborator Author

@willyborankin willyborankin Jun 26, 2023

Choose a reason for hiding this comment

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

This is a very good question! :-) Because it is forbidden to change any static, reserved and hidden resource for a non REST admin or Super admin user. TBH I'm planning to change the name after the review of the #2900 has been finished.

}

}