grafeas / kritis

Deploy-time Policy Enforcer for Kubernetes applications
https://github.com/grafeas/kritis/blob/master/docs/binary-authorization.md
Apache License 2.0
699 stars 135 forks source link

panic: interface conversion: interface is nil, not crypto.Signer #384

Open codingandcoding opened 5 years ago

codingandcoding commented 5 years ago

When I execute "go run create_attestation.go" I get the following problem: panic: interface conversion: interface is nil, not crypto.Signer. The error details are as follows:

2019/08/11 22:54:34 Connecting to Grafeas server 2019/08/11 22:54:34 Created note name:"projects/kritis/notes/att" short_description:"Generic Attestation Policy Attestor" long_description:"Generic Attestation Policy Attestor deployed in default namespace" create_time: update_time: attestation_authority:<hint:<human_readable_name:"attestation" > > in project kritis 2019/08/11 22:54:34 Listing notes... 2019/08/11 22:54:34 [name:"projects/kritis/notes/att" short_description:"Generic Attestation Policy Attestor" long_description:"Generic Attestation Policy Attestor deployed in default namespace" create_time: update_time: attestation_authority:<hint:<human_readable_name:"attestation" > > ] 2019/08/11 22:54:34 Retrieved secret for 'attestor': &{0xc00030f3d0 attestor} 2019/08/11 22:54:34 Created fingerprint: F51A1EFDA6A2B60230033CFD7ED98F12A0FDAEEB panic: interface conversion: interface is nil, not crypto.Signer

goroutine 1 [running]: github.com/grafeas/kritis/vendor/golang.org/x/crypto/openpgp/packet.(Signature).Sign(0xc0004ca000, 0x151b480, 0xc000418a00, 0xc000274d00, 0x203c4a0, 0xc000418a00, 0x0) /root/go/src/github.com/grafeas/kritis/vendor/golang.org/x/crypto/openpgp/packet/signature.go:521 +0x119 github.com/grafeas/kritis/vendor/golang.org/x/crypto/openpgp/packet.(Signature).SignUserId(0xc0004ca000, 0x0, 0x0, 0xc000404780, 0xc000274d00, 0x203c4a0, 0xc000330d80, 0x7f2339bf8400) /root/go/src/github.com/grafeas/kritis/vendor/golang.org/x/crypto/openpgp/packet/signature.go:583 +0xb0 github.com/grafeas/kritis/pkg/kritis/attestation.createEntityFromKeys(0xc000404780, 0xc000274d00, 0xc00031bb30, 0x40ced5, 0x7f233c485018) /root/go/src/github.com/grafeas/kritis/pkg/kritis/attestation/attestation.go:156 +0x2eb github.com/grafeas/kritis/pkg/kritis/attestation.CreateMessageAttestation(0xc00030f3d0, 0xc0004c80e0, 0xdf, 0xe0, 0xc0004c80e0, 0xdf, 0x0) /root/go/src/github.com/grafeas/kritis/pkg/kritis/attestation/attestation.go:102 +0x51 github.com/grafeas/kritis/pkg/kritis/util.CreateAttestationSignature(0x1386296, 0x5f, 0xc0001f6f20, 0x1, 0x1, 0xc00041f3b0, 0x28) /root/go/src/github.com/grafeas/kritis/pkg/kritis/util/util.go:83 +0xe0 main.createOccRequest(0xc0000c9ce0, 0x1) /root/go/src/github.com/grafeas/kritis/docs/standalone/create_attestation.go:135 +0x248 main.main() /root/go/src/github.com/grafeas/kritis/docs/standalone/create_attestation.go:96 +0x687 exit status 2

Has anyone encountered this problem? Is there any solution please help me?

aysylu commented 5 years ago

Could you please see if you have more than 1 key sets in your local environment by running gpg --list-keys? If so, could you please delete all of them first, then re-create in no_attestation.sh?

codingandcoding commented 5 years ago

Hello @aysylu , I have deleted all local keys and re-run "go run create_attestation.go" but still reported the above error.

ooq commented 5 years ago

Hi @codingandcoding , would the changes in #388 fix your issue? (They should have similar effect as deleting existing keys, but in a more robust way). If they do not, can you document the steps to reproduce this bug? Will look into it then. Thanks.

codingandcoding commented 5 years ago

Hi @ooq ,I tried the method in #388, but I still reported the above error, I did it according to the steps in README.md .However, the above error is reported when running the "go run create_attestation.go" script in attestation_created.sh.

codingandcoding commented 5 years ago

Hi @aysylu and @ooq , I suspect that there is a problem with the "createEntityFromKeys" method in "pkg/kritis/attestation/attestation.go" when executed to "err := e.Identities[uid.Id].SelfSignature.SignUserId(uid.Id, e. PrimaryKey, e.PrivateKey, &pgpConfig) "this line of code, the program is terminated, there is no return value.

aysylu commented 5 years ago

@codingandcoding thanks for reporting the issue! We're looking into this and were able to reproduce in some environments, but not all. @ooq is looking into this further. Just to confirm: @codingandcoding you ran the attestation_created.sh script, correct?

codingandcoding commented 5 years ago

Hi @aysylu and @ooq Thank you for your efforts. I confirmed that I ran attestation_created.sh correctly. I seem to have found the cause of this problem. Execute to err := e.Identities[uid.Id].SelfSignature.SignUserId(uid.Id, e.PrimaryKey, e.PrivateKey, &pgpConfig) in the createEntityFromKeys function in the pkg/kritis/attestation/attestation.go file. When it comes to a line statement, it seems to reference a null value. e.Identities[uid.Id].SelfSignature does not seem to have the SignUserId method. But I am not sure, please check it out. Thank you very much!

e.Identities[uid.Id] = &openpgp.Identity{ Name: uid.Id, UserId: uid, SelfSignature: &packet.Signature{ CreationTime: currentTime, SigType: packet.SigTypePositiveCert, PubKeyAlgo: packet.PubKeyAlgoRSA, Hash: pgpConfig.Hash(), IsPrimaryId: &isPrimaryID, FlagsValid: true, FlagSign: true, FlagCertify: true, IssuerKeyId: &e.PrimaryKey.KeyId, }, } err := e.Identities[uid.Id].SelfSignature.SignUserId(uid.Id, e.PrimaryKey, e.PrivateKey, &pgpConfig)

ooq commented 5 years ago

@codingandcoding That's good news! Would you mind putting together a PR on the possible fix? We can then let others experience the issue to try out the fix. Unfortunately, I ran the standalone doc earlier today again and couldn't reproduce this bug.

aysylu commented 5 years ago

@codingandcoding if you'd like to add some log statements to help with debugging (and a potential fix if you have one in mind), I'd be happy to take a look at the PR, merge the log statements and release as 0.1.1 to help with making progress with testing the end-to-end. Unfortunately, I'm not able to reproduce.:(

frayer commented 3 years ago

I know this is an old issue, but I was having a similar problem. I described a potential resolution for at least this piece in https://github.com/grafeas/kritis/issues/594#issuecomment-756421016