Skip to content

Commit

Permalink
Fix bug in owner selection when owner is present in serde (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
swaranga-netflix authored Feb 3, 2023
1 parent dd680fd commit 8203a08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ private void logOwnershipDiagnosticDetails(final QualifiedName name, final Table

log.info("Create table with invalid owner: {}. name: {}, table-dto: {}, context: {}, headers: {}",
tableOwner, name, tableDto, MetacatContextManager.getContext(), getHttpHeaders());
} else if (!isOwnerValid(MetacatContextManager.getContext().getUserName())) {
registry.counter(
"unauth.user.createTable.requestContext",
"catalog", name.getCatalogName(),
"database", name.getDatabaseName(),
"owner", StringUtils.isBlank(MetacatContextManager.getContext().getUserName()) ? "null" : tableOwner
).increment();

log.info("Create table called with invalid owner: {} in request context."
+ " name: {}, table-dto: {}, context: {}, headers: {}",
MetacatContextManager.getContext().getUserName(), name, tableDto,
MetacatContextManager.getContext(), getHttpHeaders());
}
} catch (Exception ex) {
log.warn("Error when logging diagnostic data for invalid owner table creation. name: {}, table: {}",
Expand Down Expand Up @@ -247,6 +259,7 @@ private void setOwnerIfNull(final TableDto tableDto) {
final String serdeOwner = tableDto.getSerde().getOwner();
if (isOwnerValid(serdeOwner)) {
updateTableOwner(tableDto, serdeOwner);
return;
}

// At this point, if we still have not found a valid user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ class TableServiceImplSpec extends Specification {
initialDefinitionMetadata | sessionUser | initialSerde || expectedDefMetadata | expectedSerde
null | null | null || "{}" | new StorageDto()
null | "ssarma" | null || "{\"owner\":{\"userId\":\"ssarma\"}}" | new StorageDto()
null | "root" | new StorageDto(owner: "swaranga") || "{\"owner\":{\"userId\":\"swaranga\"}}" | new StorageDto(owner: "swaranga")
"{\"owner\":{\"userId\":\"ssarma\"}}" | "asdf" | new StorageDto(owner: "swaranga") || "{\"owner\":{\"userId\":\"ssarma\"}}" | new StorageDto(owner: "swaranga")
"{\"owner\":{\"userId\":\"metacat\"}}" | "ssarma" | new StorageDto(owner: "swaranga") || "{\"owner\":{\"userId\":\"ssarma\"}}" | new StorageDto(owner: "swaranga")
"{\"owner\":{\"userId\":\"root\"}}" | "ssarma" | new StorageDto(owner: "swaranga") || "{\"owner\":{\"userId\":\"ssarma\"}}" | new StorageDto(owner: "swaranga")
Expand Down

0 comments on commit 8203a08

Please sign in to comment.