-
Notifications
You must be signed in to change notification settings - Fork 11
feat: allow api key for cavern user allocation access #256
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
Changes from 13 commits
9f260fc
f343f02
2dc660b
703aa4c
c1685cd
6fe0249
f664036
6e2995d
be234c4
9348aed
acd74ca
d379755
54b34d2
bdae2ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| ## deployable containers have a semantic and build tag | ||
| # semantic version tag: major.minor | ||
| # build version tag: timestamp | ||
| VER=0.8.5 | ||
| VER=0.8.6 | ||
| TAGS="${VER} ${VER}-$(date -u +"%Y%m%dT%H%M%S")" | ||
| unset VER |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,12 +67,14 @@ | |
|
|
||
| package org.opencadc.cavern; | ||
|
|
||
| import ca.nrc.cadc.auth.AuthenticationUtil; | ||
| import ca.nrc.cadc.auth.IdentityManager; | ||
| import ca.nrc.cadc.db.DBUtil; | ||
| import ca.nrc.cadc.rest.InitAction; | ||
| import ca.nrc.cadc.util.InvalidConfigException; | ||
| import ca.nrc.cadc.util.RsaSignatureGenerator; | ||
| import ca.nrc.cadc.uws.server.impl.InitDatabaseUWS; | ||
| import java.io.File; | ||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.LinkOption; | ||
|
|
@@ -87,6 +89,7 @@ | |
| import javax.sql.DataSource; | ||
| import org.apache.log4j.Logger; | ||
| import org.opencadc.cavern.nodes.FileSystemNodePersistence; | ||
| import org.opencadc.cavern.nodes.PosixIdentityManager; | ||
| import org.opencadc.vospace.server.NodePersistence; | ||
|
|
||
| /** | ||
|
|
@@ -103,6 +106,7 @@ public CavernInitAction() { | |
|
|
||
| @Override | ||
| public void doInit() { | ||
| initIdentityManager(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| initNodePersistence(); | ||
| initDatabase(); | ||
| } | ||
|
|
@@ -138,6 +142,25 @@ private void initNodePersistence() { | |
| log.error("Failed to create JNDI Key " + jndiNodePersistence, ex); | ||
| } | ||
| } | ||
|
|
||
| private void initIdentityManager() { | ||
| final String configuredIdentityManagerClassName = System.getProperty(IdentityManager.class.getName()); | ||
| if (configuredIdentityManagerClassName == null) { | ||
| throw new InvalidConfigException("No existing IdentityManager found. Ensure that the " + IdentityManager.class.getName() | ||
| + " System Property is set to a valid implementation."); | ||
| } | ||
|
|
||
| // Assuming there isn't more than one Cavern deployed within a JVM. | ||
| PosixIdentityManager.JNDI_NODE_PERSISTENCE_PROPERTY = this.jndiNodePersistence; | ||
|
|
||
| // To be used by the PosixIdentityManager to wrap the existing IdentityManager. | ||
| System.setProperty(PosixIdentityManager.WRAPPED_IDENTITY_MANAGER_CLASS_PROPERTY, configuredIdentityManagerClassName); | ||
|
|
||
| // Override the existing IdentityManager. | ||
| System.setProperty(IdentityManager.class.getName(), PosixIdentityManager.class.getName()); | ||
|
|
||
| log.debug("IdentityManager set to: " + PosixIdentityManager.class.getName() + " from " + configuredIdentityManagerClassName); | ||
|
pdowler marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| // generate key pair for preauth URL generation | ||
| private void initSecrets(CavernConfig conf) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,12 +68,14 @@ | |
| package org.opencadc.cavern.nodes; | ||
|
|
||
| import ca.nrc.cadc.auth.AuthenticationUtil; | ||
| import ca.nrc.cadc.auth.IdentityManager; | ||
| import ca.nrc.cadc.auth.PosixPrincipal; | ||
| import ca.nrc.cadc.io.ResourceIterator; | ||
| import ca.nrc.cadc.net.TransientException; | ||
| import ca.nrc.cadc.reg.Standards; | ||
| import ca.nrc.cadc.reg.client.LocalAuthority; | ||
| import ca.nrc.cadc.util.InvalidConfigException; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.MalformedURLException; | ||
| import java.net.URI; | ||
|
|
@@ -82,7 +84,9 @@ | |
| import java.nio.file.Files; | ||
| import java.nio.file.LinkOption; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
@@ -97,6 +101,7 @@ | |
| import org.opencadc.vospace.LinkNode; | ||
| import org.opencadc.vospace.Node; | ||
| import org.opencadc.vospace.NodeNotSupportedException; | ||
| import org.opencadc.vospace.NodeProperty; | ||
| import org.opencadc.vospace.VOS; | ||
| import org.opencadc.vospace.VOSURI; | ||
| import org.opencadc.vospace.server.LocalServiceURI; | ||
|
|
@@ -132,7 +137,7 @@ public class FileSystemNodePersistence implements NodePersistence { | |
| VOS.PROPERTY_URI_CREATOR, | ||
| VOS.PROPERTY_URI_QUOTA | ||
| )); | ||
|
|
||
| private final PosixIdentityManager identityManager; | ||
| private final GroupCache groupCache; | ||
| private final QuotaPlugin quotaImpl; | ||
|
|
@@ -144,16 +149,27 @@ public class FileSystemNodePersistence implements NodePersistence { | |
| private final CavernConfig config; | ||
| private final boolean localGroupsOnly; | ||
|
|
||
| // Set of default properties for nodes. This will be built from configuration. | ||
| private final List<NodeProperty> defaultProperties = new ArrayList<>(); | ||
|
pdowler marked this conversation as resolved.
Outdated
|
||
|
|
||
| public FileSystemNodePersistence() { | ||
| this.config = new CavernConfig(); | ||
| this.rootPath = config.getRoot(); | ||
| this.quotaImpl = config.getQuotaPlugin(); | ||
|
|
||
| defaultProperties.add(new NodeProperty(VOS.PROPERTY_URI_QUOTA, Long.toString(config.getDefaultQuotaBytes()))); | ||
|
|
||
| LocalServiceURI loc = new LocalServiceURI(config.getResourceID()); | ||
| this.rootURI = loc.getVOSBase(); | ||
|
|
||
| // must be hard coded to this and not set via java system properties | ||
| this.identityManager = new PosixIdentityManager(); | ||
| final IdentityManager configuredIdentityManager = AuthenticationUtil.getIdentityManager(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is simply a check that init did the setup correctly. The error should not be exposed to operators as a failure here is a bug, not a config issue. Instead: just catch the possible ClasscastException at line 172, eg: Yeah, I literally put "BUG" in the error message :-) |
||
|
|
||
| if (!(configuredIdentityManager instanceof PosixIdentityManager)) { | ||
| throw new InvalidConfigException("BUG: PosixIdentityManager required but found: " + configuredIdentityManager.getClass().getName()); | ||
| } | ||
|
|
||
| this.identityManager = (PosixIdentityManager) AuthenticationUtil.getIdentityManager(); | ||
|
|
||
| // root node | ||
| UUID rootID = new UUID(0L, 0L); // cosmetic: not used in cavern | ||
|
|
@@ -409,10 +425,7 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException | |
| } | ||
| node.ownerID = identityManager.toPosixPrincipal(node.owner); | ||
| } | ||
|
|
||
| //if (node.isStructured()) { | ||
| // throw new NodeNotSupportedException("StructuredDataNode is not supported."); | ||
| //} | ||
|
|
||
| if (localGroupsOnly) { | ||
| if (!node.getReadOnlyGroup().isEmpty() || !node.getReadWriteGroup().isEmpty()) { | ||
| LocalAuthority loc = new LocalAuthority(); | ||
|
|
@@ -452,6 +465,14 @@ public Node put(Node node) throws NodeNotSupportedException, TransientException | |
| throw new UnsupportedOperationException("link to external resource", ex); | ||
| } | ||
| } | ||
| } else if ((node instanceof ContainerNode) && isAllocation((ContainerNode) node) | ||
| && node.getProperty(VOS.PROPERTY_URI_QUOTA) == null) { | ||
| final NodeProperty defaultNodeProperty = this.defaultProperties.get(this.defaultProperties.indexOf(new NodeProperty(VOS.PROPERTY_URI_QUOTA))); | ||
| if (defaultNodeProperty == null) { | ||
| log.warn("No default quota (" + VOS.PROPERTY_URI_QUOTA + ") configured."); | ||
| } else { | ||
| node.getProperties().add(new NodeProperty(VOS.PROPERTY_URI_QUOTA, defaultNodeProperty.getValue())); | ||
|
pdowler marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
| // this is a complicated way to get the Path | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.