[Server] Derive the public key from private_key.der on the deprecated key-folder path

Đang mở Phù hợp với người mới
#2,363 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
authentication, security

Hướng nghiên cứu

Bắt đầu từ server/src/main/java/io/unitycatalog/server/security/SecurityConfiguration.java, trong constructor SecurityConfiguration(Path configurationFolder), khoảng dòng 70-76, nơi public_key.der được đọc riêng, và so sánh với publicKeyOf ở dòng 128, được dùng trên đường dẫn tệp khóa. Chạy SecurityConfigurationTest sau khi thêm một trường hợp có public_key.der không khớp. Hoàn thành khi một token được ký bởi cấu hình xác minh thành công và public_key.der vẫn được ghi khi sinh khóa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

enhancement good first issue

Is your feature request related to a problem? Please describe.

When server.token-signing-private-key-file is not set, the server signs its tokens with the key it keeps in etc/conf (deprecated since #2081). On that path it reads the private key from private_key.der and the public key from public_key.der as two separate files (SecurityConfiguration.java:70-76). Nothing checks that they are one pair. If they don't match (for example, one file was replaced by hand), the server starts and logs nothing, but every token it signs fails its own check, so internal tokens get a 401.

The key-file path does not have this problem: it derives the public key from the private key (publicKeyOf, line 128).

This predates #2081 (the folder path read the two files separately before it too), and it fails closed. It was raised in the review of #2081 (https://github.com/unitycatalog/unitycatalog/pull/2081#issuecomment-7123860110).

To reproduce, put a private_key.der and a public_key.der from two different openssl genrsa keys in a folder, build new SecurityConfiguration(folder), sign a token with algorithmRSA() and verify it with the same algorithm: verification fails with SignatureVerificationException.

Describe the solution you would like

  1. In SecurityConfiguration(Path configurationFolder), derive the public key from private_key.der with publicKeyOf, as the key-file path does, instead of reading public_key.der.
  2. Keep writing public_key.der when the server generates a key, so a rollback to an earlier release, which reads that file, still works.
  3. Add a row or step to the existing SecurityConfigurationTest: with a mismatched public_key.der, a token signed by the configuration verifies with it.

Additional context

Smaller follow-ups from the same review, fine to take here or separately:

  • docs/server/configuration.md, server.token-signing-private-key-file: say that a relative path resolves against the server's working directory, and that the file must exist even with authorization off.
  • No minimum key size: a 512-bit key loads and then fails when the service token is signed, with a message that does not name the file. This also predates #2081.
  • A key file path that points to a directory fails with Is a directory and no path (Files.readAllBytes, line 213); the missing, empty and encrypted cases name the file.
  • JwksOperations: the branch for a null SecurityContext exists only for JwksOperationsTest.
  • A server-level test that a token signed with another key gets HTTP 401 (today AuthDecoratorTest checks the exception, and AuthServiceTest checks 401 for an expired token).
  • writeOwnerOnly (line 160) deletes, creates, then writes the key, which is not atomic: a crash in between leaves an empty private_key.der, and the next start fails until it is removed.
Ngôn ngữ chính
Java
Star
3.6k
Fork
706
Merge trung bình
3 ngày 5 giờ
Pull request đã merge (30 ngày)
135

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của unitycatalog/unitycatalog

Tất cả issue của unitycatalog/unitycatalog

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.