Skip to content

[core] update k8s token cache hashing algorithm to Blake3#58593

Closed
andrewsykim wants to merge 1 commit intoray-project:masterfrom
andrewsykim:k8s-auth-sha256
Closed

[core] update k8s token cache hashing algorithm to Blake3#58593
andrewsykim wants to merge 1 commit intoray-project:masterfrom
andrewsykim:k8s-auth-sha256

Conversation

@andrewsykim
Copy link
Member

@andrewsykim andrewsykim commented Nov 13, 2025

Description

Follow-up PR from #58497 to update the hashing algorithm to Blake3. See #58497 (comment) for more details.

Related issues

#58497 (comment)

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

unsigned long long bitlen;
unsigned int state[8];
} SHA256_CTX;
} ray_SHA256_CTX;
Copy link
Member Author

Choose a reason for hiding this comment

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

Rename is requried due to definition conflict w/ openssl libs:

    In file included from external/boringssl/src/include/openssl/conf.h:60,
                     from external/boost/boost/asio/ssl/detail/openssl_types.hpp:23,
                     from external/boost/boost/asio/ssl/error.hpp:20,
                     from src/ray/rpc/authentication/k8s_util.cc:19:
    external/boringssl/src/include/openssl/base.h:353:32: error: conflicting declaration 'typedef struct sha256_state_st SHA256_CTX'

@andrewsykim andrewsykim changed the title [WIP] update k8s token cache hashing algorithm to SHA256 [core] update k8s token cache hashing algorithm to Blake3 Nov 14, 2025
@andrewsykim andrewsykim force-pushed the k8s-auth-sha256 branch 3 times, most recently from 94b0d39 to eb7affc Compare November 14, 2025 03:39
@andrewsykim andrewsykim marked this pull request as ready for review November 14, 2025 03:41
@andrewsykim andrewsykim requested a review from a team as a code owner November 14, 2025 03:41
@andrewsykim
Copy link
Member Author

@sampan-s-nayak @richo-anyscale PTAL

Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
@sampan-s-nayak sampan-s-nayak added the go add ONLY when ready to merge, run all tests label Nov 14, 2025
":blake3_avx512",
],
visibility=["//visibility:public"],
)
Copy link

Choose a reason for hiding this comment

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

Bug: BLAKE3: ARM Builds Lack Performance Optimizations

The BLAKE3 build configuration only includes x86-specific SIMD optimizations (blake3_sse2, blake3_sse41, blake3_avx2, blake3_avx512) with x86-specific compiler flags (-msse2, -msse4.1, -mavx2, -mavx512f). ARM platforms like Apple Silicon or AWS Graviton won't get optimized NEON implementations, resulting in significantly degraded hashing performance. BLAKE3 supports ARM NEON but those implementations aren't included in this build file.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

if this is true then it may lead to errors, we will probably need to support all env's

@sampan-s-nayak sampan-s-nayak requested a review from a team November 14, 2025 04:16
@@ -110,9 +114,17 @@ class AuthenticationToken {
/// Get token hash
/// @return Hash of the token value
std::size_t ToHash() const {
Copy link
Contributor

Choose a reason for hiding this comment

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

we are using just the first 8 bytes of BLAKE3's 32byte output, this will work fine but now I am wondering if using BLAKE3 is an overkill for this usecase (I thought we wanted to use the entire hash not just a std::size_t so sorry about the confusion)

on reading a bit more on this topic it looks like using BLAKE3 like this can still be a good choice as we can avoid collision attacks, but I am not sure if we want that level of security.

Copy link
Contributor

Choose a reason for hiding this comment

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

@richo-anyscale let me know your thoughts on this, if the benefits are not worth the effort I feel we can skip this for now. I am not sure about the effort required for fixing #58593 (comment) so would prefer not to spend time on this if possible

Copy link
Contributor

Choose a reason for hiding this comment

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

So I've spent a while thinking about it and I'm just not really worried about this as a sidechannel.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tend to agree, will close this PR, we can revisit this in the future

@sampan-s-nayak sampan-s-nayak self-requested a review November 14, 2025 04:24
@ray-gardener ray-gardener bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Nov 14, 2025
std::size_t hash_value;
std::memcpy(&hash_value, output, sizeof(hash_value));

return hash_value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we consider caching this? How frequently will ToHash() get called? The original function likely performs quite a bit faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants