Skip to content

Add noop jurisdictions in workerd #4745

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

Merged
1 commit merged into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/workerd/api/actor.c++
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ jsg::Ref<DurableObject> DurableObjectNamespace::getImpl(jsg::Lock& js,
}

jsg::Ref<DurableObjectNamespace> DurableObjectNamespace::jurisdiction(
jsg::Lock& js, kj::String jurisdiction) {
auto newIdFactory = idFactory->cloneWithJurisdiction(jurisdiction);
jsg::Lock& js, jsg::Optional<kj::String> maybeJurisdiction) {
auto newIdFactory = idFactory->cloneWithJurisdiction(maybeJurisdiction);

KJ_SWITCH_ONEOF(channel) {
KJ_CASE_ONEOF(channelId, uint) {
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/api/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ class DurableObjectNamespace: public jsg::Object {
jsg::Lock& js, jsg::Ref<DurableObjectId> id, jsg::Optional<GetDurableObjectOptions> options);

// Creates a subnamespace with the jurisdiction hardcoded.
jsg::Ref<DurableObjectNamespace> jurisdiction(jsg::Lock& js, kj::String jurisdiction);
jsg::Ref<DurableObjectNamespace> jurisdiction(
jsg::Lock& js, jsg::Optional<kj::String> maybeJurisdiction);

JSG_RESOURCE_TYPE(DurableObjectNamespace, CompatibilityFlags::Reader flags) {
JSG_METHOD(newUniqueId);
Expand Down
3 changes: 2 additions & 1 deletion src/workerd/io/actor-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class ActorIdFactory {
virtual kj::Own<ActorId> idFromName(kj::String name) = 0;
virtual kj::Own<ActorId> idFromString(kj::String str) = 0;
virtual bool matchesJurisdiction(const ActorId& id) = 0;
virtual kj::Own<ActorIdFactory> cloneWithJurisdiction(kj::StringPtr jurisdiction) = 0;
virtual kj::Own<ActorIdFactory> cloneWithJurisdiction(
kj::Maybe<kj::StringPtr> maybeJurisdiction) = 0;
};

} // namespace workerd
11 changes: 10 additions & 1 deletion src/workerd/server/actor-id-impl.c++
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ActorIdFactoryImpl::ActorIdFactoryImpl(kj::StringPtr uniqueKey) {
KJ_ASSERT(SHA256(uniqueKey.asBytes().begin(), uniqueKey.size(), key) == key);
}

ActorIdFactoryImpl::ActorIdFactoryImpl(const kj::byte keyParam[SHA256_DIGEST_LENGTH]) {
memcpy(key, keyParam, sizeof(key));
}

kj::Own<ActorIdFactory::ActorId> ActorIdFactoryImpl::newUniqueId(
kj::Maybe<kj::StringPtr> jurisdiction) {
JSG_REQUIRE(
Expand Down Expand Up @@ -90,7 +94,12 @@ kj::Own<ActorIdFactory::ActorId> ActorIdFactoryImpl::idFromString(kj::String str
return kj::heap<ActorIdImpl>(id, kj::none);
}

kj::Own<ActorIdFactory> ActorIdFactoryImpl::cloneWithJurisdiction(kj::StringPtr jurisdiction) {
kj::Own<ActorIdFactory> ActorIdFactoryImpl::cloneWithJurisdiction(
kj::Maybe<kj::StringPtr> maybeJurisdiction) {
if (maybeJurisdiction == kj::none) {
return kj::heap<ActorIdFactoryImpl>(key);
}

JSG_FAIL_REQUIRE(Error, "Jurisdiction restrictions are not implemented in workerd.");
}

Expand Down
5 changes: 4 additions & 1 deletion src/workerd/server/actor-id-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace workerd::server {
class ActorIdFactoryImpl final: public ActorIdFactory {
public:
ActorIdFactoryImpl(kj::StringPtr uniqueKey);
ActorIdFactoryImpl(const kj::byte keyParam[SHA256_DIGEST_LENGTH]);

class ActorIdImpl final: public ActorId {
public:
ActorIdImpl(const kj::byte idParam[SHA256_DIGEST_LENGTH], kj::Maybe<kj::String> name);
Expand All @@ -29,7 +31,8 @@ class ActorIdFactoryImpl final: public ActorIdFactory {
kj::Own<ActorId> newUniqueId(kj::Maybe<kj::StringPtr> jurisdiction) override;
kj::Own<ActorId> idFromName(kj::String name) override;
kj::Own<ActorId> idFromString(kj::String str) override;
kj::Own<ActorIdFactory> cloneWithJurisdiction(kj::StringPtr jurisdiction) override;
kj::Own<ActorIdFactory> cloneWithJurisdiction(
kj::Maybe<kj::StringPtr> maybeJurisdiction) override;
bool matchesJurisdiction(const ActorId& id) override;

private:
Expand Down
Loading