provisioners.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. package authority
  2. import (
  3. "context"
  4. "crypto/x509"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/smallstep/certificates/authority/admin"
  8. "github.com/smallstep/certificates/authority/config"
  9. "github.com/smallstep/certificates/authority/provisioner"
  10. "github.com/smallstep/certificates/errs"
  11. "go.step.sm/crypto/jose"
  12. "go.step.sm/linkedca"
  13. "gopkg.in/square/go-jose.v2/jwt"
  14. )
  15. // GetEncryptedKey returns the JWE key corresponding to the given kid argument.
  16. func (a *Authority) GetEncryptedKey(kid string) (string, error) {
  17. a.adminMutex.RLock()
  18. defer a.adminMutex.RUnlock()
  19. key, ok := a.provisioners.LoadEncryptedKey(kid)
  20. if !ok {
  21. return "", errs.NotFound("encrypted key with kid %s was not found", kid)
  22. }
  23. return key, nil
  24. }
  25. // GetProvisioners returns a map listing each provisioner and the JWK Key Set
  26. // with their public keys.
  27. func (a *Authority) GetProvisioners(cursor string, limit int) (provisioner.List, string, error) {
  28. a.adminMutex.RLock()
  29. defer a.adminMutex.RUnlock()
  30. provisioners, nextCursor := a.provisioners.Find(cursor, limit)
  31. return provisioners, nextCursor, nil
  32. }
  33. // LoadProvisionerByCertificate returns an interface to the provisioner that
  34. // provisioned the certificate.
  35. func (a *Authority) LoadProvisionerByCertificate(crt *x509.Certificate) (provisioner.Interface, error) {
  36. a.adminMutex.RLock()
  37. defer a.adminMutex.RUnlock()
  38. p, ok := a.provisioners.LoadByCertificate(crt)
  39. if !ok {
  40. return nil, admin.NewError(admin.ErrorNotFoundType, "unable to load provisioner from certificate")
  41. }
  42. return p, nil
  43. }
  44. // LoadProvisionerByToken returns an interface to the provisioner that
  45. // provisioned the token.
  46. func (a *Authority) LoadProvisionerByToken(token *jwt.JSONWebToken, claims *jwt.Claims) (provisioner.Interface, error) {
  47. a.adminMutex.RLock()
  48. defer a.adminMutex.RUnlock()
  49. p, ok := a.provisioners.LoadByToken(token, claims)
  50. if !ok {
  51. return nil, admin.NewError(admin.ErrorNotFoundType, "unable to load provisioner from token")
  52. }
  53. return p, nil
  54. }
  55. // LoadProvisionerByID returns an interface to the provisioner with the given ID.
  56. func (a *Authority) LoadProvisionerByID(id string) (provisioner.Interface, error) {
  57. a.adminMutex.RLock()
  58. defer a.adminMutex.RUnlock()
  59. p, ok := a.provisioners.Load(id)
  60. if !ok {
  61. return nil, admin.NewError(admin.ErrorNotFoundType, "provisioner %s not found", id)
  62. }
  63. return p, nil
  64. }
  65. // LoadProvisionerByName returns an interface to the provisioner with the given Name.
  66. func (a *Authority) LoadProvisionerByName(name string) (provisioner.Interface, error) {
  67. a.adminMutex.RLock()
  68. defer a.adminMutex.RUnlock()
  69. p, ok := a.provisioners.LoadByName(name)
  70. if !ok {
  71. return nil, admin.NewError(admin.ErrorNotFoundType, "provisioner %s not found", name)
  72. }
  73. return p, nil
  74. }
  75. func (a *Authority) generateProvisionerConfig(ctx context.Context) (*provisioner.Config, error) {
  76. // Merge global and configuration claims
  77. claimer, err := provisioner.NewClaimer(a.config.AuthorityConfig.Claims, config.GlobalProvisionerClaims)
  78. if err != nil {
  79. return nil, err
  80. }
  81. // TODO: should we also be combining the ssh federated roots here?
  82. // If we rotate ssh roots keys, sshpop provisioner will lose ability to
  83. // validate old SSH certificates, unless they are added as federated certs.
  84. sshKeys, err := a.GetSSHRoots(ctx)
  85. if err != nil {
  86. return nil, err
  87. }
  88. return &provisioner.Config{
  89. Claims: claimer.Claims(),
  90. Audiences: a.config.GetAudiences(),
  91. DB: a.db,
  92. SSHKeys: &provisioner.SSHKeys{
  93. UserKeys: sshKeys.UserKeys,
  94. HostKeys: sshKeys.HostKeys,
  95. },
  96. GetIdentityFunc: a.getIdentityFunc,
  97. }, nil
  98. }
  99. // StoreProvisioner stores an provisioner.Interface to the authority.
  100. func (a *Authority) StoreProvisioner(ctx context.Context, prov *linkedca.Provisioner) error {
  101. a.adminMutex.Lock()
  102. defer a.adminMutex.Unlock()
  103. certProv, err := ProvisionerToCertificates(prov)
  104. if err != nil {
  105. return admin.WrapErrorISE(err,
  106. "error converting to certificates provisioner from linkedca provisioner")
  107. }
  108. if _, ok := a.provisioners.LoadByName(prov.GetName()); ok {
  109. return admin.NewError(admin.ErrorBadRequestType,
  110. "provisioner with name %s already exists", prov.GetName())
  111. }
  112. if _, ok := a.provisioners.LoadByTokenID(certProv.GetIDForToken()); ok {
  113. return admin.NewError(admin.ErrorBadRequestType,
  114. "provisioner with token ID %s already exists", certProv.GetIDForToken())
  115. }
  116. // Store to database -- this will set the ID.
  117. if err := a.adminDB.CreateProvisioner(ctx, prov); err != nil {
  118. return admin.WrapErrorISE(err, "error creating admin")
  119. }
  120. // We need a new conversion that has the newly set ID.
  121. certProv, err = ProvisionerToCertificates(prov)
  122. if err != nil {
  123. return admin.WrapErrorISE(err,
  124. "error converting to certificates provisioner from linkedca provisioner")
  125. }
  126. provisionerConfig, err := a.generateProvisionerConfig(ctx)
  127. if err != nil {
  128. return admin.WrapErrorISE(err, "error generating provisioner config")
  129. }
  130. if err := certProv.Init(*provisionerConfig); err != nil {
  131. return admin.WrapErrorISE(err, "error initializing provisioner %s", prov.Name)
  132. }
  133. if err := a.provisioners.Store(certProv); err != nil {
  134. if err := a.reloadAdminResources(ctx); err != nil {
  135. return admin.WrapErrorISE(err, "error reloading admin resources on failed provisioner store")
  136. }
  137. return admin.WrapErrorISE(err, "error storing provisioner in authority cache")
  138. }
  139. return nil
  140. }
  141. // UpdateProvisioner stores an provisioner.Interface to the authority.
  142. func (a *Authority) UpdateProvisioner(ctx context.Context, nu *linkedca.Provisioner) error {
  143. a.adminMutex.Lock()
  144. defer a.adminMutex.Unlock()
  145. certProv, err := ProvisionerToCertificates(nu)
  146. if err != nil {
  147. return admin.WrapErrorISE(err,
  148. "error converting to certificates provisioner from linkedca provisioner")
  149. }
  150. provisionerConfig, err := a.generateProvisionerConfig(ctx)
  151. if err != nil {
  152. return admin.WrapErrorISE(err, "error generating provisioner config")
  153. }
  154. if err := certProv.Init(*provisionerConfig); err != nil {
  155. return admin.WrapErrorISE(err, "error initializing provisioner %s", nu.Name)
  156. }
  157. if err := a.provisioners.Update(certProv); err != nil {
  158. return admin.WrapErrorISE(err, "error updating provisioner '%s' in authority cache", nu.Name)
  159. }
  160. if err := a.adminDB.UpdateProvisioner(ctx, nu); err != nil {
  161. if err := a.reloadAdminResources(ctx); err != nil {
  162. return admin.WrapErrorISE(err, "error reloading admin resources on failed provisioner update")
  163. }
  164. return admin.WrapErrorISE(err, "error updating provisioner '%s'", nu.Name)
  165. }
  166. return nil
  167. }
  168. // RemoveProvisioner removes an provisioner.Interface from the authority.
  169. func (a *Authority) RemoveProvisioner(ctx context.Context, id string) error {
  170. a.adminMutex.Lock()
  171. defer a.adminMutex.Unlock()
  172. p, ok := a.provisioners.Load(id)
  173. if !ok {
  174. return admin.NewError(admin.ErrorBadRequestType,
  175. "provisioner %s not found", id)
  176. }
  177. provName, provID := p.GetName(), p.GetID()
  178. // Validate
  179. // - Check that there will be SUPER_ADMINs that remain after we
  180. // remove this provisioner.
  181. if a.admins.SuperCount() == a.admins.SuperCountByProvisioner(provName) {
  182. return admin.NewError(admin.ErrorBadRequestType,
  183. "cannot remove provisioner %s because no super admins will remain", provName)
  184. }
  185. // Delete all admins associated with the provisioner.
  186. admins, ok := a.admins.LoadByProvisioner(provName)
  187. if ok {
  188. for _, adm := range admins {
  189. if err := a.removeAdmin(ctx, adm.Id); err != nil {
  190. return admin.WrapErrorISE(err, "error deleting admin %s, as part of provisioner %s deletion", adm.Subject, provName)
  191. }
  192. }
  193. }
  194. // Remove provisioner from authority caches.
  195. if err := a.provisioners.Remove(provID); err != nil {
  196. return admin.WrapErrorISE(err, "error removing admin from authority cache")
  197. }
  198. // Remove provisioner from database.
  199. if err := a.adminDB.DeleteProvisioner(ctx, provID); err != nil {
  200. if err := a.reloadAdminResources(ctx); err != nil {
  201. return admin.WrapErrorISE(err, "error reloading admin resources on failed provisioner remove")
  202. }
  203. return admin.WrapErrorISE(err, "error deleting provisioner %s", provName)
  204. }
  205. return nil
  206. }
  207. func CreateFirstProvisioner(ctx context.Context, db admin.DB, password string) (*linkedca.Provisioner, error) {
  208. jwk, jwe, err := jose.GenerateDefaultKeyPair([]byte(password))
  209. if err != nil {
  210. return nil, admin.WrapErrorISE(err, "error generating JWK key pair")
  211. }
  212. jwkPubBytes, err := jwk.MarshalJSON()
  213. if err != nil {
  214. return nil, admin.WrapErrorISE(err, "error marshaling JWK")
  215. }
  216. jwePrivStr, err := jwe.CompactSerialize()
  217. if err != nil {
  218. return nil, admin.WrapErrorISE(err, "error serializing JWE")
  219. }
  220. p := &linkedca.Provisioner{
  221. Name: "Admin JWK",
  222. Type: linkedca.Provisioner_JWK,
  223. Details: &linkedca.ProvisionerDetails{
  224. Data: &linkedca.ProvisionerDetails_JWK{
  225. JWK: &linkedca.JWKProvisioner{
  226. PublicKey: jwkPubBytes,
  227. EncryptedPrivateKey: []byte(jwePrivStr),
  228. },
  229. },
  230. },
  231. Claims: &linkedca.Claims{
  232. X509: &linkedca.X509Claims{
  233. Enabled: true,
  234. Durations: &linkedca.Durations{
  235. Default: "5m",
  236. },
  237. },
  238. },
  239. }
  240. if err := db.CreateProvisioner(ctx, p); err != nil {
  241. return nil, admin.WrapErrorISE(err, "error creating provisioner")
  242. }
  243. return p, nil
  244. }
  245. func ValidateClaims(c *linkedca.Claims) error {
  246. if c == nil {
  247. return nil
  248. }
  249. if c.X509 != nil {
  250. if c.X509.Durations != nil {
  251. if err := ValidateDurations(c.X509.Durations); err != nil {
  252. return err
  253. }
  254. }
  255. }
  256. if c.Ssh != nil {
  257. if c.Ssh.UserDurations != nil {
  258. if err := ValidateDurations(c.Ssh.UserDurations); err != nil {
  259. return err
  260. }
  261. }
  262. if c.Ssh.HostDurations != nil {
  263. if err := ValidateDurations(c.Ssh.HostDurations); err != nil {
  264. return err
  265. }
  266. }
  267. }
  268. return nil
  269. }
  270. func ValidateDurations(d *linkedca.Durations) error {
  271. var (
  272. err error
  273. min, max, def *provisioner.Duration
  274. )
  275. if d.Min != "" {
  276. min, err = provisioner.NewDuration(d.Min)
  277. if err != nil {
  278. return admin.WrapError(admin.ErrorBadRequestType, err, "min duration '%s' is invalid", d.Min)
  279. }
  280. if min.Value() < 0 {
  281. return admin.WrapError(admin.ErrorBadRequestType, err, "min duration '%s' cannot be less than 0", d.Min)
  282. }
  283. }
  284. if d.Max != "" {
  285. max, err = provisioner.NewDuration(d.Max)
  286. if err != nil {
  287. return admin.WrapError(admin.ErrorBadRequestType, err, "max duration '%s' is invalid", d.Max)
  288. }
  289. if max.Value() < 0 {
  290. return admin.WrapError(admin.ErrorBadRequestType, err, "max duration '%s' cannot be less than 0", d.Max)
  291. }
  292. }
  293. if d.Default != "" {
  294. def, err = provisioner.NewDuration(d.Default)
  295. if err != nil {
  296. return admin.WrapError(admin.ErrorBadRequestType, err, "default duration '%s' is invalid", d.Default)
  297. }
  298. if def.Value() < 0 {
  299. return admin.WrapError(admin.ErrorBadRequestType, err, "default duration '%s' cannot be less than 0", d.Default)
  300. }
  301. }
  302. if d.Min != "" && d.Max != "" && min.Value() > max.Value() {
  303. return admin.NewError(admin.ErrorBadRequestType,
  304. "min duration '%s' cannot be greater than max duration '%s'", d.Min, d.Max)
  305. }
  306. if d.Min != "" && d.Default != "" && min.Value() > def.Value() {
  307. return admin.NewError(admin.ErrorBadRequestType,
  308. "min duration '%s' cannot be greater than default duration '%s'", d.Min, d.Default)
  309. }
  310. if d.Default != "" && d.Max != "" && min.Value() > def.Value() {
  311. return admin.NewError(admin.ErrorBadRequestType,
  312. "default duration '%s' cannot be greater than max duration '%s'", d.Default, d.Max)
  313. }
  314. return nil
  315. }
  316. func provisionerListToCertificates(l []*linkedca.Provisioner) (provisioner.List, error) {
  317. var nu provisioner.List
  318. for _, p := range l {
  319. certProv, err := ProvisionerToCertificates(p)
  320. if err != nil {
  321. return nil, err
  322. }
  323. nu = append(nu, certProv)
  324. }
  325. return nu, nil
  326. }
  327. func optionsToCertificates(p *linkedca.Provisioner) *provisioner.Options {
  328. ops := &provisioner.Options{
  329. X509: &provisioner.X509Options{},
  330. SSH: &provisioner.SSHOptions{},
  331. }
  332. if p.X509Template != nil {
  333. ops.X509.Template = string(p.X509Template.Template)
  334. ops.X509.TemplateData = p.X509Template.Data
  335. }
  336. if p.SshTemplate != nil {
  337. ops.SSH.Template = string(p.SshTemplate.Template)
  338. ops.SSH.TemplateData = p.SshTemplate.Data
  339. }
  340. return ops
  341. }
  342. func durationsToCertificates(d *linkedca.Durations) (min, max, def *provisioner.Duration, err error) {
  343. if len(d.Min) > 0 {
  344. min, err = provisioner.NewDuration(d.Min)
  345. if err != nil {
  346. return nil, nil, nil, admin.WrapErrorISE(err, "error parsing minimum duration '%s'", d.Min)
  347. }
  348. }
  349. if len(d.Max) > 0 {
  350. max, err = provisioner.NewDuration(d.Max)
  351. if err != nil {
  352. return nil, nil, nil, admin.WrapErrorISE(err, "error parsing maximum duration '%s'", d.Max)
  353. }
  354. }
  355. if len(d.Default) > 0 {
  356. def, err = provisioner.NewDuration(d.Default)
  357. if err != nil {
  358. return nil, nil, nil, admin.WrapErrorISE(err, "error parsing default duration '%s'", d.Default)
  359. }
  360. }
  361. return
  362. }
  363. // claimsToCertificates converts the linkedca provisioner claims type to the
  364. // certifictes claims type.
  365. func claimsToCertificates(c *linkedca.Claims) (*provisioner.Claims, error) {
  366. if c == nil {
  367. return nil, nil
  368. }
  369. pc := &provisioner.Claims{
  370. DisableRenewal: &c.DisableRenewal,
  371. }
  372. var err error
  373. if xc := c.X509; xc != nil {
  374. if d := xc.Durations; d != nil {
  375. pc.MinTLSDur, pc.MaxTLSDur, pc.DefaultTLSDur, err = durationsToCertificates(d)
  376. if err != nil {
  377. return nil, err
  378. }
  379. }
  380. }
  381. if sc := c.Ssh; sc != nil {
  382. pc.EnableSSHCA = &sc.Enabled
  383. if d := sc.UserDurations; d != nil {
  384. pc.MinUserSSHDur, pc.MaxUserSSHDur, pc.DefaultUserSSHDur, err = durationsToCertificates(d)
  385. if err != nil {
  386. return nil, err
  387. }
  388. }
  389. if d := sc.HostDurations; d != nil {
  390. pc.MinHostSSHDur, pc.MaxHostSSHDur, pc.DefaultHostSSHDur, err = durationsToCertificates(d)
  391. if err != nil {
  392. return nil, err
  393. }
  394. }
  395. }
  396. return pc, nil
  397. }
  398. // ProvisionerToCertificates converts the linkedca provisioner type to the certificates provisioner
  399. // interface.
  400. func ProvisionerToCertificates(p *linkedca.Provisioner) (provisioner.Interface, error) {
  401. claims, err := claimsToCertificates(p.Claims)
  402. if err != nil {
  403. return nil, err
  404. }
  405. details := p.Details.GetData()
  406. if details == nil {
  407. return nil, fmt.Errorf("provisioner does not have any details")
  408. }
  409. options := optionsToCertificates(p)
  410. switch d := details.(type) {
  411. case *linkedca.ProvisionerDetails_JWK:
  412. jwk := new(jose.JSONWebKey)
  413. if err := json.Unmarshal(d.JWK.PublicKey, &jwk); err != nil {
  414. return nil, err
  415. }
  416. return &provisioner.JWK{
  417. ID: p.Id,
  418. Type: p.Type.String(),
  419. Name: p.Name,
  420. Key: jwk,
  421. EncryptedKey: string(d.JWK.EncryptedPrivateKey),
  422. Claims: claims,
  423. Options: options,
  424. }, nil
  425. case *linkedca.ProvisionerDetails_X5C:
  426. var roots []byte
  427. for i, root := range d.X5C.GetRoots() {
  428. if i > 0 {
  429. roots = append(roots, '\n')
  430. }
  431. roots = append(roots, root...)
  432. }
  433. return &provisioner.X5C{
  434. ID: p.Id,
  435. Type: p.Type.String(),
  436. Name: p.Name,
  437. Roots: roots,
  438. Claims: claims,
  439. Options: options,
  440. }, nil
  441. case *linkedca.ProvisionerDetails_K8SSA:
  442. var publicKeys []byte
  443. for i, k := range d.K8SSA.GetPublicKeys() {
  444. if i > 0 {
  445. publicKeys = append(publicKeys, '\n')
  446. }
  447. publicKeys = append(publicKeys, k...)
  448. }
  449. return &provisioner.K8sSA{
  450. ID: p.Id,
  451. Type: p.Type.String(),
  452. Name: p.Name,
  453. PubKeys: publicKeys,
  454. Claims: claims,
  455. Options: options,
  456. }, nil
  457. case *linkedca.ProvisionerDetails_SSHPOP:
  458. return &provisioner.SSHPOP{
  459. ID: p.Id,
  460. Type: p.Type.String(),
  461. Name: p.Name,
  462. Claims: claims,
  463. }, nil
  464. case *linkedca.ProvisionerDetails_ACME:
  465. cfg := d.ACME
  466. return &provisioner.ACME{
  467. ID: p.Id,
  468. Type: p.Type.String(),
  469. Name: p.Name,
  470. ForceCN: cfg.ForceCn,
  471. Claims: claims,
  472. Options: options,
  473. }, nil
  474. case *linkedca.ProvisionerDetails_OIDC:
  475. cfg := d.OIDC
  476. return &provisioner.OIDC{
  477. ID: p.Id,
  478. Type: p.Type.String(),
  479. Name: p.Name,
  480. TenantID: cfg.TenantId,
  481. ClientID: cfg.ClientId,
  482. ClientSecret: cfg.ClientSecret,
  483. ConfigurationEndpoint: cfg.ConfigurationEndpoint,
  484. Admins: cfg.Admins,
  485. Domains: cfg.Domains,
  486. Groups: cfg.Groups,
  487. ListenAddress: cfg.ListenAddress,
  488. Claims: claims,
  489. Options: options,
  490. }, nil
  491. case *linkedca.ProvisionerDetails_AWS:
  492. cfg := d.AWS
  493. instanceAge, err := parseInstanceAge(cfg.InstanceAge)
  494. if err != nil {
  495. return nil, err
  496. }
  497. return &provisioner.AWS{
  498. ID: p.Id,
  499. Type: p.Type.String(),
  500. Name: p.Name,
  501. Accounts: cfg.Accounts,
  502. DisableCustomSANs: cfg.DisableCustomSans,
  503. DisableTrustOnFirstUse: cfg.DisableTrustOnFirstUse,
  504. InstanceAge: instanceAge,
  505. Claims: claims,
  506. Options: options,
  507. }, nil
  508. case *linkedca.ProvisionerDetails_GCP:
  509. cfg := d.GCP
  510. instanceAge, err := parseInstanceAge(cfg.InstanceAge)
  511. if err != nil {
  512. return nil, err
  513. }
  514. return &provisioner.GCP{
  515. ID: p.Id,
  516. Type: p.Type.String(),
  517. Name: p.Name,
  518. ServiceAccounts: cfg.ServiceAccounts,
  519. ProjectIDs: cfg.ProjectIds,
  520. DisableCustomSANs: cfg.DisableCustomSans,
  521. DisableTrustOnFirstUse: cfg.DisableTrustOnFirstUse,
  522. InstanceAge: instanceAge,
  523. Claims: claims,
  524. Options: options,
  525. }, nil
  526. case *linkedca.ProvisionerDetails_Azure:
  527. cfg := d.Azure
  528. return &provisioner.Azure{
  529. ID: p.Id,
  530. Type: p.Type.String(),
  531. Name: p.Name,
  532. TenantID: cfg.TenantId,
  533. ResourceGroups: cfg.ResourceGroups,
  534. Audience: cfg.Audience,
  535. DisableCustomSANs: cfg.DisableCustomSans,
  536. DisableTrustOnFirstUse: cfg.DisableTrustOnFirstUse,
  537. Claims: claims,
  538. Options: options,
  539. }, nil
  540. default:
  541. return nil, fmt.Errorf("provisioner %s not implemented", p.Type)
  542. }
  543. }
  544. func parseInstanceAge(age string) (provisioner.Duration, error) {
  545. var instanceAge provisioner.Duration
  546. if age != "" {
  547. iap, err := provisioner.NewDuration(age)
  548. if err != nil {
  549. return instanceAge, err
  550. }
  551. instanceAge = *iap
  552. }
  553. return instanceAge, nil
  554. }