adb014 commented on code in PR #1116: URL: https://github.com/apache/guacamole-client/pull/1116#discussion_r3093230385
########## extensions/guacamole-vault/modules/guacamole-vault-hv/src/main/java/org/apache/guacamole/vault/hv/conf/HvAttributeService.java: ########## @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.vault.hv.conf; + +import com.google.inject.Singleton; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.form.BooleanField; +import org.apache.guacamole.form.Form; +import org.apache.guacamole.form.TextField; +import org.apache.guacamole.language.TranslatableGuacamoleClientException; +import org.apache.guacamole.vault.conf.VaultAttributeService; + +@Singleton +public class HvAttributeService implements VaultAttributeService { + + /** + * The name of the attribute which can contain a HV configuration blob + * associated with either a connection group or user. + */ + public static final String HV_CONFIGURATION_ATTRIBUTE = "hv-config"; Review Comment: Wouldn't it be better to use roleID and secretID that use an opaque base64 encoded json blob containing the token ? ########## extensions/guacamole-vault/modules/guacamole-vault-hv/src/main/java/org/apache/guacamole/vault/hv/secret/HvClient.java: ########## @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.vault.hv.secret; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.Future; +import javax.annotation.Nullable; +import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.vault.hv.GuacamoleExceptionSupplier; +import org.apache.guacamole.vault.hv.conf.HvConfigurationService; +import org.apache.guacamole.vault.hv.secret.HvTimedSecretData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Client which retrieves records from Hashicorp Vault. + */ +public class HvClient { + + /** + * Name of the HTTP header for the token, as specified in documentation: + * https://developer.hashicorp.com/vault/docs/auth/token + */ + static final String HASHICORP_VAULT_HTTP_HEADER_TOKEN = "X-Vault-Token"; + + /** + * API version. + */ + static final String HASHICORP_VAULT_HTTP_VERSION = "/v1/"; Review Comment: If allowing both Hashicorp and OpenBao to use the same jar file, this should allow /v2/ as well ########## extensions/guacamole-vault/modules/guacamole-vault-hv/src/main/java/org/apache/guacamole/vault/hv/secret/HvClient.java: ########## @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.vault.hv.secret; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; Review Comment: Wouldn't it be better to use org.springframework.vault and delegate all of http communication and reuse and concurrency issues to spring ? See my propsed code block in #1143 ########## extensions/guacamole-vault/modules/guacamole-vault-hv/src/main/java/org/apache/guacamole/vault/hv/secret/HvClient.java: ########## @@ -0,0 +1,270 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.guacamole.vault.hv.secret; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.assistedinject.AssistedInject; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.Future; +import javax.annotation.Nullable; +import org.apache.guacamole.GuacamoleException; +import org.apache.guacamole.vault.hv.GuacamoleExceptionSupplier; +import org.apache.guacamole.vault.hv.conf.HvConfigurationService; +import org.apache.guacamole.vault.hv.secret.HvTimedSecretData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Client which retrieves records from Hashicorp Vault. + */ +public class HvClient { + + /** + * Name of the HTTP header for the token, as specified in documentation: + * https://developer.hashicorp.com/vault/docs/auth/token + */ + static final String HASHICORP_VAULT_HTTP_HEADER_TOKEN = "X-Vault-Token"; + + /** + * API version. + */ + static final String HASHICORP_VAULT_HTTP_VERSION = "/v1/"; + + /** + * Name of the Guacamole token to resolve on a Hashicorp Vault (secret path + * is set in the token modifier). + */ + static final String HASHICORP_VAULT_TOKEN_PREFIX = "HASHIVAULT:"; + + /** + * Logger for this class. + */ + private static final Logger logger = LoggerFactory.getLogger(HvClient.class); + + /** + * HttpClient for this class. + */ + private final HttpClient httpClient; + + /** + * ObjectMapper for this class. + */ + private final ObjectMapper objectMapper; + + /** + * The HV configuration associated with this client instance. + */ + private final Map<String, String> hvConfig; + + /** + * The maximum amount of time that an entry will be stored in the cache + * before being refreshed, in milliseconds. + */ + private long cacheLifetime; Review Comment: If delegated to org.springframework.vault, cache is withn the spring framework. I also has an issue with caching values within Guacamole in that highly sensitive data might end up swapped to disk and not in memory and more easily attackable. If caching is used, need to think about how to avoid cache leaks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
