Skip to content

Conversation

@lishuxu
Copy link
Contributor

@lishuxu lishuxu commented Jan 2, 2026

feat: add restcatalog authentication api

/// \param properties Configuration properties.
/// \return A session for initialization, or the catalog session by default.
virtual std::shared_ptr<AuthSession> InitSession(
HttpClient* init_client,
Copy link
Contributor

Choose a reason for hiding this comment

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

why use raw pointer?🤔 use std::shared_ptr instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AuthManager simply borrows the HTTP client owned by the catalog, it isn’t supposed to manage that client’s lifetime, so here use raw pointer.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it is better to use HttpClient& to save the null check?

Comment on lines +18 to +23
set(ICEBERG_REST_AUTH_SOURCES auth_session.cc auth_manager.cc auth_managers.cc)

# Expose sources to parent scope for inclusion in iceberg_rest library
set(ICEBERG_REST_AUTH_SOURCES
${ICEBERG_REST_AUTH_SOURCES}
PARENT_SCOPE)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
set(ICEBERG_REST_AUTH_SOURCES auth_session.cc auth_manager.cc auth_managers.cc)
# Expose sources to parent scope for inclusion in iceberg_rest library
set(ICEBERG_REST_AUTH_SOURCES
${ICEBERG_REST_AUTH_SOURCES}
PARENT_SCOPE)
iceberg_install_all_headers(iceberg/catalog/rest/auth)

The current pattern is inconsistent with other CMake config. We should only install headers for this subdirectory here.

Comment on lines +32 to +36
# Add auth sources with proper path prefix
foreach(AUTH_SOURCE ${ICEBERG_REST_AUTH_SOURCES})
list(APPEND ICEBERG_REST_SOURCES "auth/${AUTH_SOURCE}")
endforeach()

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Add auth sources with proper path prefix
foreach(AUTH_SOURCE ${ICEBERG_REST_AUTH_SOURCES})
list(APPEND ICEBERG_REST_SOURCES "auth/${AUTH_SOURCE}")
endforeach()

Let's remove these lines by directly adding those files in the above set(ICEBERG_REST_SOURCES).

# specific language governing permissions and limitations
# under the License.

# Include auth subdirectory
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Include auth subdirectory

This comment is unnecessary.


} // namespace iceberg::rest

namespace iceberg::rest::auth {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need the extra auth namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here mirrors the Java package structure (org.apache.iceberg.rest.auth), making it easier to navigate between implementations.

Comment on lines +31 to +37
/// \brief Convert a string to lowercase for case-insensitive comparison.
std::string ToLower(std::string_view str) {
std::string result(str);
std::ranges::transform(result, result.begin(),
[](unsigned char c) { return std::tolower(c); });
return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a StringUtils::ToLower func in util/string_util.h

Comment on lines +36 to +38
void Close() override {
// No resources to release
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be removed if do nothing.

/// \brief Authentication manager interface for REST catalog.

namespace iceberg::rest {
class HttpClient;
Copy link
Member

Choose a reason for hiding this comment

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

Remove this by include type_fwd.h.

#include <string>
#include <unordered_map>

#include "iceberg/catalog/rest/auth/auth_session.h"
Copy link
Member

Choose a reason for hiding this comment

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

Remove this to use forward declaration.

Comment on lines +47 to +48
///
/// This interface is modeled after Java Iceberg's AuthManager interface.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
///
/// This interface is modeled after Java Iceberg's AuthManager interface.

/// \param properties Configuration properties.
/// \return A session for initialization, or the catalog session by default.
virtual std::shared_ptr<AuthSession> InitSession(
HttpClient* init_client,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it is better to use HttpClient& to save the null check?

/// \param properties Configuration properties (merged with server config).
/// \return A session for catalog operations, or an error if session creation fails
/// (e.g., missing required credentials, network failure during token fetch).
virtual Result<std::shared_ptr<AuthSession>> CatalogSession(
Copy link
Member

Choose a reason for hiding this comment

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

ditto

/// (i.e., request headers take precedence).
///
/// \param headers The headers map to add authentication information to.
void Authenticate(std::unordered_map<std::string, std::string>& headers) override;
Copy link
Member

Choose a reason for hiding this comment

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

Do you think it is worth adding a class HttpRequest? We don't have it yet.

/// OAuth2 authentication. Otherwise, defaults to no authentication.
///
/// This behavior is consistent with Java Iceberg's AuthManagers.
std::string InferAuthType(
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a enum class for the auth type?

} // namespace

std::unordered_map<std::string, AuthManagerFactory>& AuthManagers::GetRegistry() {
static std::unordered_map<std::string, AuthManagerFactory> registry;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static std::unordered_map<std::string, AuthManagerFactory> registry;
static std::unordered_map<std::string, AuthManagerFactory, StringHash, StringEqual> registry;

Let's support heterogeneous lookup


private:
/// \brief Get the global registry of auth manager factories.
static std::unordered_map<std::string, AuthManagerFactory>& GetRegistry();
Copy link
Member

Choose a reason for hiding this comment

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

We don't need this function in the header file, right?

/// other properties (e.g., presence of "credential" or "token" implies oauth2).
/// If no auth-related properties are found, it defaults to "none".
///
/// \param name A name for the manager (used for logging).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// \param name A name for the manager (used for logging).
/// \param name A name for the manager.

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.

4 participants