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

Change CreatedAt types for KMS from string to time.Time #296

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

marktheunissen
Copy link
Contributor

@marktheunissen marktheunissen commented Aug 8, 2024

@klauspost
Copy link
Contributor

Are any of the fields currently used? A bit worried about old minio + new mc.

Copy link
Contributor

@ramondeklein ramondeklein left a comment

Choose a reason for hiding this comment

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

@ramondeklein
Copy link
Contributor

@klauspost You're right. The most common used client would be mc and because the JSON marshalling wasn't set to omitempty, it will probably contain an empty string when used with old MinIO clients. We may want to use custom unmarshalling that is able to deal with an empty string and translate it to "no time".

Copy link
Contributor

@ramondeklein ramondeklein left a comment

Choose a reason for hiding this comment

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

Please add custom unmarshalling for:

func (k *KMSKeyInfo) UnmarshalJSON(data []byte) error
func (k *KMSPolicyInfo) UnmarshalJSON(data []byte) error
func (k *KMSIdentityInfo) UnmarshalJSON(data []byte) error
func (k *KMSDescribePolicy) UnmarshalJSON(data []byte) error
func (k *KMSDescribeIdentity) UnmarshalJSON(data []byte) error

@klauspost
Copy link
Contributor

https://go.dev/play/p/7RUcboegpkz - yeah... It even triggers an error on empty strings :(

@marktheunissen
Copy link
Contributor Author

marktheunissen commented Aug 9, 2024

Are any of the fields currently used?

4/5 of the structs aren't used anywhere meaningfully, that I can see. Think they are just vestigal. I would prefer to remove them, if we can? Please check my searches below:

The only place that catches my attention is in miniohq/minio:master which is a 2 year old master branch fork. I think that maybe the functionality once existed in MinIO and was removed.

The most common used client would be mc and because the JSON marshalling wasn't set to omitempty, it will probably contain an empty string when used with old MinIO clients.

For KMSKeyInfo, by sheer luck and for an unknown reason, the current JSON marshalling is done with a different struct kes.KeyInfo, which uses a time.Time for CreatedAt, see: https://github.com/minio/minio/blob/master/cmd/kms-handlers.go#L224-L234

Which means existing builds of MinIO respond as follows:

127.0.0.1:9000 GET /minio/kms/v1/key/list?pattern=%2A
127.0.0.1:9000 Proto: HTTP/1.1
127.0.0.1:9000 Host: 127.0.0.1:9000
...
127.0.0.1:9000 [RESPONSE] [2024-08-09T10:55:45.447] [ Duration 637µs TTFB 636µs ↑ 93 B  ↓ 60 B ]
127.0.0.1:9000 200 OK
127.0.0.1:9000 Content-Type: application/json
127.0.0.1:9000 Accept-Ranges: bytes
127.0.0.1:9000 Content-Length: 60
127.0.0.1:9000 Server: MinIO
127.0.0.1:9000 [{"name":"default-key","created_at":"0001-01-01T00:00:00Z"}]
127.0.0.1:9000

(I would paste some test commands for play.min.io here but it's currently offline for maintenance)

The struct kes.KeyInfo does use omitempty in Marshalling, however it is not effective on time.Times, which have non-empty zero value: https://github.com/minio/kms-go/blob/main/kes/key.go#L88-L110

To be effective it would have had to use time.IsZero and a pointer, here is how it should have worked: (comment/uncomment the Marshal function: https://play.golang.com/p/zCfC8oopWiu). Do we want to reproduce this pattern on KMSKeyInfo? It would probably be cleaner to other languages to omit the created_at key, but for Go, I'm not sure how much it really matters since Go can detect zero value timestamps.

So what about other KMSKeyInfo usage? Here is a search:

I don't see anything noteworthy in the above results.

This is a bit of a rabbit hole, I think to summarize my preferred actions are just to remove all the structs except KMSKeyInfo and not do any override of the unmarshalling.

If you guys spot errors or potential issues in my reasoning, please link directly to lines of code so I can follow up and test, thanks.

@ramondeklein
Copy link
Contributor

ramondeklein commented Aug 9, 2024

Please check my searches below:

Note that these searches are not really valid. If you call madmin.ListKeys(), then it returns []madmin.KMSKeyInfo, but it won't show up in this search. But I can confirm that CreatedBy is never accessed from inside mc.

I don't think we will have any issues. Go serializes a time.Time structure as a string too ("2009-11-10T23:00:00Z"). So even if clients expect a string, then they'll get a string.

@marktheunissen
Copy link
Contributor Author

@klauspost Happy with the above? :)

@marktheunissen marktheunissen merged commit 1785292 into minio:main Aug 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants