Skip to content

Commit

Permalink
Exporter: Fix Executing as Non-Root User
Browse files Browse the repository at this point in the history
The TokenStore class checked access when initializing. When running the
exporter as non-root user with a Hub, that has authentication disabled,
then access to the token store is not necessary. This is the case for
the tutorial.
  • Loading branch information
holesch committed Aug 16, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent fdb2a6d commit b3e5813
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions not_my_board/_auth/_login.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ def __init__(self, hub_url, http_client, token_store_path):
self._show_claims = None
self._token_store = _TokenStore(token_store_path)

# fail early, if user doesn't have permission
self._token_store.check_access()

async def _context_stack(self, stack):
url = f"{self._hub_url}/api/v1/auth-info"
auth_info = await self._http.get_json(url)
@@ -114,16 +117,15 @@ async def get_id_token(self):

class _TokenStore(util.ContextStack):
def __init__(self, path_str=None):
path = pathlib.Path(path_str)

if not path.exists():
path.parent.mkdir(parents=True, exist_ok=True)
path.touch(mode=0o600)
self._path = pathlib.Path(path_str)

if not os.access(path, os.R_OK | os.W_OK):
raise RuntimeError(f"Not allowed to access {path}")
def check_access(self):
if not self._path.exists():
self._path.parent.mkdir(parents=True, exist_ok=True)
self._path.touch(mode=0o600)

self._path = path
if not os.access(self._path, os.R_OK | os.W_OK):
raise RuntimeError(f"Not allowed to access {self._path}")

async def _context_stack(self, stack):
self._f = stack.enter_context(self._path.open("r+"))

0 comments on commit b3e5813

Please sign in to comment.