Skip to content
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

Harbor not properly sharing CSRF tokens/sessions across scaled deployment in k8s #21060

Closed
ianseyer opened this issue Oct 17, 2024 · 3 comments · Fixed by #21154
Closed

Harbor not properly sharing CSRF tokens/sessions across scaled deployment in k8s #21060

ianseyer opened this issue Oct 17, 2024 · 3 comments · Fixed by #21154
Assignees

Comments

@ianseyer
Copy link

ianseyer commented Oct 17, 2024

When using the UI, I will sporadically see "CSRF token invalid" errors when performing actions when harbor-core is scaled to >1.

  1. Scale up harbor-core to 3 replicas
  2. Create several projects
  3. attempt to delete them one by one
  4. you will see "CSRF token invalid" errors sporadically

This was confirmed by scaling harbor-core down to 1, and then deletions worked consistently without issue.

On Harbor 2.11.0

@MinerYang
Copy link
Contributor

MinerYang commented Oct 21, 2024

Hi @ianseyer ,

Could your check following settings?

  • Please verify that env CSRF_KEY in each of the core pod are the same
  • Please check if each of the node that running harbor-core pod are with same machine time
  • Please kindly check if there's any debug logs you could provide while error happened.

@ianseyer
Copy link
Author

ianseyer commented Oct 21, 2024

So, interestingly, I am seeing:

harbor-staging-core-d5d6cb4b-qbvx2 2024-10-21T16:17:03Z [WARNING] [/server/middleware/csrf/csrf.go:71]: Invalid CSRF
 key from environment: 8Yl=jR?eF@n[...]faPs, generating random key...

Should I be ensuring that the csrf key follows some particular form, or is exclusively alphanumeric?

EDIT: I now see - the length must be 32: https://github.com/goharbor/harbor/blob/main/src/server/middleware/csrf/csrf.go#L70

@MinerYang
Copy link
Contributor

MinerYang commented Oct 22, 2024

True, you need to make sure the key be 32 characters otherwise harbor would randomly generate a key for use and only work for core replicas=1, otherwise it would failed. So if you specified yourself xsrfkey in harbor-helm values.yaml, please make sure it is legit.
And we will add more comments and validations while harbor instance pre-installed.

wy65701436 added a commit to wy65701436/harbor that referenced this issue Nov 8, 2024
Fixes goharbor#21060

Do not generate a random key if the provided key has an invalid length.

Signed-off-by: wang yan <[email protected]>
wy65701436 added a commit to wy65701436/harbor that referenced this issue Nov 8, 2024
Fixes goharbor#21060

Do not generate a random key if the provided key has an invalid length.

Signed-off-by: wang yan <[email protected]>
wy65701436 added a commit to wy65701436/harbor that referenced this issue Nov 8, 2024
Fixes goharbor#21060

Do not generate a random key if the provided key has an invalid length.

Signed-off-by: wang yan <[email protected]>
wy65701436 added a commit that referenced this issue Nov 15, 2024
* update csrf key generation

Fixes #21060

Do not generate a random key if the provided key has an invalid length.

Signed-off-by: wang yan <[email protected]>

* fix ut check

Signed-off-by: wang yan <[email protected]>

---------

Signed-off-by: wang yan <[email protected]>
ianseyer pushed a commit to ianseyer/harbor that referenced this issue Feb 3, 2025
* update csrf key generation

Fixes goharbor#21060

Do not generate a random key if the provided key has an invalid length.

Signed-off-by: wang yan <[email protected]>

* fix ut check

Signed-off-by: wang yan <[email protected]>

---------

Signed-off-by: wang yan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants