├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── api └── pubkeystore.pb.go ├── main.go ├── proto └── pubkeystore.proto └── server └── server.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.pem 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution, 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | 3 | RUN set -ex; \ 4 | apk add --no-cache --no-progress --virtual .build-deps git gcc musl-dev bash go; \ 5 | env GOPATH=/go go get -v github.com/google/pubkeystore; \ 6 | install -t /bin /go/bin/pubkeystore; \ 7 | rm -rf /go; \ 8 | apk --no-progress del .build-deps 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | api/pubkeystore.pb.go: proto/pubkeystore.proto 2 | mkdir -p api 3 | cd proto && protoc -I/usr/local/include -I. \ 4 | -I${GOPATH}/src \ 5 | -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \ 6 | --go_out=Mgoogle/api/annotations.proto=github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/google/api,plugins=grpc:../api \ 7 | pubkeystore.proto 8 | 9 | clean: 10 | rm -rf api/*.pb.go 11 | 12 | .PHONY: clean 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PubkeyStore 2 | 3 | [![Docker Repository on Quay](https://quay.io/repository/picoprod/pubkeystore/status "Docker Repository on Quay")](https://quay.io/repository/picoprod/pubkeystore) 4 | 5 | **This is not an official Google product** 6 | 7 | PubkeyStore is a ssh key management server, that provides public keys upon request, to be used with metaserver for VM seeding. 8 | 9 | You can find all the currently exposed APIs in `proto/pubkeystore.proto`. 10 | -------------------------------------------------------------------------------- /api/pubkeystore.pb.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2017 Google Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | */ 18 | 19 | // Code generated by protoc-gen-go. 20 | // source: pubkeystore.proto 21 | // DO NOT EDIT! 22 | 23 | /* 24 | Package api is a generated protocol buffer package. 25 | 26 | It is generated from these files: 27 | pubkeystore.proto 28 | 29 | It has these top-level messages: 30 | SSHKey 31 | GetKeysRequest 32 | GetKeysReply 33 | */ 34 | package api 35 | 36 | import proto "github.com/golang/protobuf/proto" 37 | import fmt "fmt" 38 | import math "math" 39 | 40 | import ( 41 | context "golang.org/x/net/context" 42 | grpc "google.golang.org/grpc" 43 | ) 44 | 45 | // Reference imports to suppress errors if they are not otherwise used. 46 | var _ = proto.Marshal 47 | var _ = fmt.Errorf 48 | var _ = math.Inf 49 | 50 | // This is a compile-time assertion to ensure that this generated file 51 | // is compatible with the proto package it is being compiled against. 52 | // A compilation error at this line likely means your copy of the 53 | // proto package needs to be updated. 54 | const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package 55 | 56 | type SSHKey struct { 57 | Name string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` 58 | Algo string `protobuf:"bytes,2,opt,name=algo" json:"algo,omitempty"` 59 | Pubkey string `protobuf:"bytes,3,opt,name=pubkey" json:"pubkey,omitempty"` 60 | Comment string `protobuf:"bytes,4,opt,name=comment" json:"comment,omitempty"` 61 | } 62 | 63 | func (m *SSHKey) Reset() { *m = SSHKey{} } 64 | func (m *SSHKey) String() string { return proto.CompactTextString(m) } 65 | func (*SSHKey) ProtoMessage() {} 66 | func (*SSHKey) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} } 67 | 68 | func (m *SSHKey) GetName() string { 69 | if m != nil { 70 | return m.Name 71 | } 72 | return "" 73 | } 74 | 75 | func (m *SSHKey) GetAlgo() string { 76 | if m != nil { 77 | return m.Algo 78 | } 79 | return "" 80 | } 81 | 82 | func (m *SSHKey) GetPubkey() string { 83 | if m != nil { 84 | return m.Pubkey 85 | } 86 | return "" 87 | } 88 | 89 | func (m *SSHKey) GetComment() string { 90 | if m != nil { 91 | return m.Comment 92 | } 93 | return "" 94 | } 95 | 96 | type GetKeysRequest struct { 97 | VmName string `protobuf:"bytes,1,opt,name=vm_name,json=vmName" json:"vm_name,omitempty"` 98 | } 99 | 100 | func (m *GetKeysRequest) Reset() { *m = GetKeysRequest{} } 101 | func (m *GetKeysRequest) String() string { return proto.CompactTextString(m) } 102 | func (*GetKeysRequest) ProtoMessage() {} 103 | func (*GetKeysRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} } 104 | 105 | func (m *GetKeysRequest) GetVmName() string { 106 | if m != nil { 107 | return m.VmName 108 | } 109 | return "" 110 | } 111 | 112 | type GetKeysReply struct { 113 | Keys []*SSHKey `protobuf:"bytes,1,rep,name=keys" json:"keys,omitempty"` 114 | } 115 | 116 | func (m *GetKeysReply) Reset() { *m = GetKeysReply{} } 117 | func (m *GetKeysReply) String() string { return proto.CompactTextString(m) } 118 | func (*GetKeysReply) ProtoMessage() {} 119 | func (*GetKeysReply) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} } 120 | 121 | func (m *GetKeysReply) GetKeys() []*SSHKey { 122 | if m != nil { 123 | return m.Keys 124 | } 125 | return nil 126 | } 127 | 128 | func init() { 129 | proto.RegisterType((*SSHKey)(nil), "api.SSHKey") 130 | proto.RegisterType((*GetKeysRequest)(nil), "api.GetKeysRequest") 131 | proto.RegisterType((*GetKeysReply)(nil), "api.GetKeysReply") 132 | } 133 | 134 | // Reference imports to suppress errors if they are not otherwise used. 135 | var _ context.Context 136 | var _ grpc.ClientConn 137 | 138 | // This is a compile-time assertion to ensure that this generated file 139 | // is compatible with the grpc package it is being compiled against. 140 | const _ = grpc.SupportPackageIsVersion4 141 | 142 | // Client API for PubkeyStore service 143 | 144 | type PubkeyStoreClient interface { 145 | GetKeys(ctx context.Context, in *GetKeysRequest, opts ...grpc.CallOption) (*GetKeysReply, error) 146 | } 147 | 148 | type pubkeyStoreClient struct { 149 | cc *grpc.ClientConn 150 | } 151 | 152 | func NewPubkeyStoreClient(cc *grpc.ClientConn) PubkeyStoreClient { 153 | return &pubkeyStoreClient{cc} 154 | } 155 | 156 | func (c *pubkeyStoreClient) GetKeys(ctx context.Context, in *GetKeysRequest, opts ...grpc.CallOption) (*GetKeysReply, error) { 157 | out := new(GetKeysReply) 158 | err := grpc.Invoke(ctx, "/api.PubkeyStore/GetKeys", in, out, c.cc, opts...) 159 | if err != nil { 160 | return nil, err 161 | } 162 | return out, nil 163 | } 164 | 165 | // Server API for PubkeyStore service 166 | 167 | type PubkeyStoreServer interface { 168 | GetKeys(context.Context, *GetKeysRequest) (*GetKeysReply, error) 169 | } 170 | 171 | func RegisterPubkeyStoreServer(s *grpc.Server, srv PubkeyStoreServer) { 172 | s.RegisterService(&_PubkeyStore_serviceDesc, srv) 173 | } 174 | 175 | func _PubkeyStore_GetKeys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 176 | in := new(GetKeysRequest) 177 | if err := dec(in); err != nil { 178 | return nil, err 179 | } 180 | if interceptor == nil { 181 | return srv.(PubkeyStoreServer).GetKeys(ctx, in) 182 | } 183 | info := &grpc.UnaryServerInfo{ 184 | Server: srv, 185 | FullMethod: "/api.PubkeyStore/GetKeys", 186 | } 187 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 188 | return srv.(PubkeyStoreServer).GetKeys(ctx, req.(*GetKeysRequest)) 189 | } 190 | return interceptor(ctx, in, info, handler) 191 | } 192 | 193 | var _PubkeyStore_serviceDesc = grpc.ServiceDesc{ 194 | ServiceName: "api.PubkeyStore", 195 | HandlerType: (*PubkeyStoreServer)(nil), 196 | Methods: []grpc.MethodDesc{ 197 | { 198 | MethodName: "GetKeys", 199 | Handler: _PubkeyStore_GetKeys_Handler, 200 | }, 201 | }, 202 | Streams: []grpc.StreamDesc{}, 203 | Metadata: "pubkeystore.proto", 204 | } 205 | 206 | func init() { proto.RegisterFile("pubkeystore.proto", fileDescriptor0) } 207 | 208 | var fileDescriptor0 = []byte{ 209 | // 218 bytes of a gzipped FileDescriptorProto 210 | 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x51, 0x4b, 0x87, 0x30, 211 | 0x14, 0xc5, 0x33, 0x65, 0xd2, 0x35, 0x82, 0xff, 0x0d, 0x6a, 0xf4, 0xd2, 0x9f, 0x3d, 0xfd, 0x7b, 212 | 0x31, 0xd0, 0x6f, 0xd0, 0x4b, 0x81, 0x10, 0xa1, 0x1f, 0x20, 0x66, 0x5c, 0x42, 0x72, 0x6e, 0xe9, 213 | 0x14, 0xf6, 0xed, 0x63, 0xd3, 0x22, 0xdf, 0xee, 0xfd, 0x9d, 0xb3, 0x9d, 0xb3, 0xc1, 0xc1, 0xcc, 214 | 0xed, 0x17, 0xb9, 0xc9, 0xea, 0x91, 0x72, 0x33, 0x6a, 0xab, 0x31, 0x96, 0xa6, 0x13, 0x2d, 0xb0, 215 | 0xa6, 0x79, 0xa9, 0xc8, 0x21, 0x42, 0x32, 0x48, 0x45, 0x3c, 0x3a, 0x46, 0xa7, 0x8b, 0x3a, 0xcc, 216 | 0x9e, 0xc9, 0xfe, 0x53, 0xf3, 0xf3, 0x95, 0xf9, 0x19, 0x6f, 0x80, 0xad, 0x77, 0xf1, 0x38, 0xd0, 217 | 0x6d, 0x43, 0x0e, 0xe9, 0x87, 0x56, 0x8a, 0x06, 0xcb, 0x93, 0x20, 0xfc, 0xae, 0xe2, 0x01, 0xae, 218 | 0x9e, 0xc9, 0x56, 0xe4, 0xa6, 0x9a, 0xbe, 0x67, 0x9a, 0x2c, 0xde, 0x42, 0xba, 0xa8, 0xf7, 0x7f, 219 | 0x71, 0x6c, 0x51, 0xaf, 0x52, 0x91, 0x78, 0x84, 0xcb, 0x3f, 0xab, 0xe9, 0x1d, 0xde, 0x43, 0xe2, 220 | 0x5b, 0xf3, 0xe8, 0x18, 0x9f, 0xb2, 0x22, 0xcb, 0xa5, 0xe9, 0xf2, 0xb5, 0x6f, 0x1d, 0x84, 0xe2, 221 | 0x09, 0xb2, 0xb7, 0x90, 0xdf, 0xf8, 0x97, 0x61, 0x09, 0xe9, 0x76, 0x1e, 0xaf, 0x83, 0x79, 0x1f, 222 | 0x7c, 0x77, 0xd8, 0x43, 0xd3, 0x3b, 0x71, 0xd6, 0xb2, 0xf0, 0x1f, 0xe5, 0x4f, 0x00, 0x00, 0x00, 223 | 0xff, 0xff, 0xc0, 0x19, 0x77, 0xc9, 0x24, 0x01, 0x00, 0x00, 224 | } 225 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2017 Google Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "flag" 23 | "strings" 24 | 25 | "github.com/golang/glog" 26 | "github.com/google/go-microservice-helpers/server" 27 | "github.com/google/go-microservice-helpers/tracing" 28 | 29 | pb "github.com/google/pubkeystore/api" 30 | "github.com/google/pubkeystore/server" 31 | ) 32 | 33 | type staticKeysFlag []string 34 | 35 | func (sk *staticKeysFlag) String() string { 36 | if sk == nil { 37 | return "" 38 | } 39 | return strings.Join(*sk, ",") 40 | } 41 | 42 | func (sk *staticKeysFlag) Set(value string) error { 43 | *sk = append(*sk, value) 44 | return nil 45 | } 46 | 47 | var ( 48 | staticKeys staticKeysFlag 49 | ) 50 | 51 | func main() { 52 | flag.Var(&staticKeys, "static-key", "openssh key to announce") 53 | flag.Parse() 54 | defer glog.Flush() 55 | 56 | err := tracing.InitTracer(*serverhelpers.ListenAddress, "keyserver") 57 | if err != nil { 58 | glog.Fatalf("failed to init tracing interface: %v", err) 59 | } 60 | 61 | grpcServer, credstoreClient, err := serverhelpers.NewServer() 62 | if err != nil { 63 | glog.Fatalf("failed to init GRPC server: %v", err) 64 | } 65 | if credstoreClient == nil { 66 | glog.Fatalf("failed to init credstore") 67 | } 68 | 69 | svr := server.NewServer(staticKeys) 70 | 71 | pb.RegisterPubkeyStoreServer(grpcServer, &svr) 72 | 73 | err = serverhelpers.ListenAndServe(grpcServer, nil) 74 | if err != nil { 75 | glog.Fatalf("failed to serve: %v", err) 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /proto/pubkeystore.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package api; 4 | 5 | message SSHKey { 6 | string name = 1; 7 | string algo = 2; 8 | string pubkey = 3; 9 | string comment = 4; 10 | } 11 | 12 | message GetKeysRequest { 13 | string vm_name = 1; 14 | } 15 | 16 | message GetKeysReply { 17 | repeated SSHKey keys = 1; 18 | } 19 | 20 | service PubkeyStore { 21 | rpc GetKeys(GetKeysRequest) returns (GetKeysReply) {} 22 | } 23 | -------------------------------------------------------------------------------- /server/server.go: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright 2017 Google Inc. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | */ 18 | 19 | package server 20 | 21 | import ( 22 | "strings" 23 | 24 | "golang.org/x/net/context" 25 | 26 | pb "github.com/google/pubkeystore/api" 27 | ) 28 | 29 | // Server is GRPC server. 30 | type Server struct { 31 | staticKeys []*pb.SSHKey 32 | } 33 | 34 | // NewServer creates a new server instance. 35 | func NewServer(keys []string) Server { 36 | parsedKeys := make([]*pb.SSHKey, len(keys)) 37 | for i, k := range keys { 38 | parsedKeys[i] = parseKey(k) 39 | } 40 | return Server{staticKeys: parsedKeys} 41 | } 42 | 43 | func parseKey(key string) *pb.SSHKey { 44 | parts := strings.SplitN(key, " ", 3) 45 | return &pb.SSHKey{ 46 | Name: "static-key", 47 | Algo: parts[0], 48 | Pubkey: parts[1], 49 | Comment: parts[2], 50 | } 51 | } 52 | 53 | // GetKeys is GRPC handler for GetKeys API. 54 | func (s Server) GetKeys(context.Context, *pb.GetKeysRequest) (*pb.GetKeysReply, error) { 55 | repl := &pb.GetKeysReply{} 56 | repl.Keys = s.staticKeys 57 | 58 | return repl, nil 59 | } 60 | --------------------------------------------------------------------------------