defenseunicorns / pepr

Type safe K8s middleware for humans
https://pepr.dev
Apache License 2.0
146 stars 11 forks source link

Pepr Store Keys Need Sanitization #915

Open cmwylie19 opened 3 weeks ago

cmwylie19 commented 3 weeks ago

Describe what should be investigated or refactored

Certain keys are not making it into the store, the patch operation is returning 422.

image

We need a way to sanitize the key so that the patch operation succeeds and users of the store can get their data in a consistent manner.

We ran into an issue in a few spots where we accept arbitrary keycloak client ids in our Package CR and then use those in other resources without "sanitizing" them. One of those places was the pepr store - we were setting weird client IDs like https://google.com/ for testing and then our pepr store key had that in it and failed during set. Just want to make sure we know what is allowed for those key names.

Reproduce:

When(a.Pod)
  .IsCreatedOrUpdated()
  .Mutate(po => {
    Log.info("Pod created or updated", po);
    //Store.setItem(`${po.Raw.metadata!.name}`, "a");
    Store.setItem(`https://google.com-${po.Raw.metadata!.name}`, "bcd");
  });

Definition of done:

Links to any relevant code

/src/lib/controller/store.ts

Additional context

Add any other context or screenshots about the technical debt here.

mjnagel commented 3 weeks ago

This would be a pretty big value add for uds-core. We started to go down the route of figuring out our own sanitization but were struggling with:

If pepr handled this in a way that we could just set and keys and be guaranteed that set/get calls would succeed and not retrieve the wrong value that would be great for our use case.

cmwylie19 commented 3 weeks ago

In researching other edge-cases, size does not seem to be a limitation.

    let longString = 'a'.repeat(253);
    const longerString = longString.repeat(1000);
    Store.setItem(longerString, longString);
cmwylie19 commented 3 weeks ago

Moving to the next milestone since we need to plan with UDS Core how to roll this out to prod users