Files
snapd/store/devicenauthctx.go
Andrew Phelps ec12734fa2 store, o/storecontext, o/devicestate, o/c/configcore: use store.access to disable access to snap store (#13198)
* o/c/configcore: add store.access configurable to allow store access to be disable

* o/devicestate: expose store.access via the storeContextBackend

* overlord,o/storecontext: expose store.access via storecontext.storeContext

* store: use store.access to disable access to snap store when using methods store.Store

* configcore: add tests for validation of store.access

* store: test offline store functionality

* o/storecontext: add test case for StoreAccess

* store, o/c/configcore, o/storecontext: remove usage of online as valid value for store.access

* store: correct ErrStoreOffline message

* store: add unit test to check that http retries do not happen when store is offline

* store: rename isStoreOnline to checkStoreOnline for consistency

* store: remove outdated comment

* o/c/configcore: convert handleStoreAccess to be a fsOnlyHandler since it does not need state

* store: disable more instances of store network access

* overlord,o/storecontext: combine ProxyStoreer and StoreAccessQuerier into one interface

* o/devicestate: add test for storeContextBackend.StoreAccess

* store: modify Store.endpointURL to check if the store is offline

* o/storecontext: simplify TestStoreAccess test case

* store: make Store.assertionsEndpointURL return an error if the store is offline

* store: add more test cases for an offline store

* o/devicestate: remove outdated comment

* store: remove outdated comment

* store: fix outdated comments

* store: test that SnapAction returns an error when the store is offline

* store: clarify ErrStoreOffline message

* o/c/configcore: move store.access registration for more general use

* o/c/configcore, dirs: write config file for snap-repair in store.access handler

* cmd/snap-repair: consume snap repair config file to check if store access is offline

* overlord: remove accidental goimports change

* image: set root dir to temp dir for tests

* o/c/configcore: remove build flags from store.go

* store: rename checkStoreOnline to checkStoreOffline for consistency

* Revert "store: rename checkStoreOnline to checkStoreOffline for consistency"

This reverts commit dd07e487127964c417eeac11d1d954a5d1132469.

* cmd/snap-repair, o/c/configcore: use unexported repairConfig for configuring snap-repair

* o/c/configcore: fix broken test following type rename

* o/c/configcore: remove defined error to make future modifications less error-prone

* o/c/configcore: remove superfluous $

* store, o/devicestate, o/storecontext: change StoreAccess methods to StoreOffline methods that return a boolean indicator

* dirs, o/c/configcore: make sure to check fsOnlyContext for a different root dir

* cmd/snap-repair: move this change into a seperate PR

* o/c/configcore: fixup some comments

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>

* o/c/configcore: add test for setting store.access on filesystem only apply

---------

Co-authored-by: Miguel Pires <miguelpires94@gmail.com>
2023-09-27 15:27:21 -04:00

71 lines
2.1 KiB
Go

// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2016-2019 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package store
import (
"errors"
"net/url"
"github.com/snapcore/snapd/asserts"
"github.com/snapcore/snapd/overlord/auth"
)
// A DeviceAndAuthContext mediates access to device and auth information for the store.
type DeviceAndAuthContext interface {
Device() (*auth.DeviceState, error)
UpdateDeviceAuth(device *auth.DeviceState, sessionMacaroon string) (actual *auth.DeviceState, err error)
UpdateUserAuth(user *auth.UserState, discharges []string) (actual *auth.UserState, err error)
StoreID(fallback string) (string, error)
DeviceSessionRequestParams(nonce string) (*DeviceSessionRequestParams, error)
ProxyStoreParams(defaultURL *url.URL) (proxyStoreID string, proxySroreURL *url.URL, err error)
CloudInfo() (*auth.CloudInfo, error)
StoreOffline() (bool, error)
}
// DeviceSessionRequestParams gathers the assertions and information to be sent to request a device session.
type DeviceSessionRequestParams struct {
Request *asserts.DeviceSessionRequest
Serial *asserts.Serial
Model *asserts.Model
}
func (p *DeviceSessionRequestParams) EncodedRequest() string {
return string(asserts.Encode(p.Request))
}
func (p *DeviceSessionRequestParams) EncodedSerial() string {
return string(asserts.Encode(p.Serial))
}
func (p *DeviceSessionRequestParams) EncodedModel() string {
return string(asserts.Encode(p.Model))
}
var (
// ErrNoSerial indicates that a device serial is not set yet.
ErrNoSerial = errors.New("no device serial yet")
)