Skip to content

Commit

Permalink
Handle error when there are no roots returned by CA Service (#298)
Browse files Browse the repository at this point in the history
This occurs when authentication is not properly set up. Otherwise,
the service crashes with a nil pointer dereference.

Signed-off-by: Hayden Blauzvern <hblauzvern@google.com>
  • Loading branch information
haydentherapper authored Dec 23, 2021
1 parent f361af5 commit cd4f5c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/ca/googleca/v1/googleca.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ func (c *CertAuthorityService) Root(ctx context.Context) ([]byte, error) {
if done == iterator.Done {
break
}
if done != nil {
break
}
pems += strings.Join(c.PemCaCertificates, "")
}
c.cachedRoots = []byte(pems)
})
if len(c.cachedRoots) == 0 {
return c.cachedRoots, fmt.Errorf("error fetching root certificates")
}
return c.cachedRoots, nil
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/ca/googleca/v1beta1/googleca.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,16 @@ func (c *CertAuthorityService) Root(ctx context.Context) ([]byte, error) {
if done == iterator.Done {
break
}
if done != nil {
break
}
pems += strings.Join(c.PemCaCertificates, "")
}
c.cachedRoots = []byte(pems)
})
if len(c.cachedRoots) == 0 {
return c.cachedRoots, fmt.Errorf("error fetching root certificates")
}
return c.cachedRoots, nil
}

Expand Down

0 comments on commit cd4f5c0

Please sign in to comment.