Skip to content

Commit

Permalink
fix: bugfixes for auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Feb 1, 2024
1 parent 4a1f326 commit 427792c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
25 changes: 20 additions & 5 deletions backrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ func main() {
}

// Create the authenticator
secret := make([]byte, 32)
if n, err := rand.Read(secret); err != nil || n != 32 {
zap.S().Fatalf("Error generating secret: %v", err)
}
authenticator := auth.NewAuthenticator(secret, configStore)
authenticator := auth.NewAuthenticator(getSecret(), configStore)

var wg sync.WaitGroup

Expand Down Expand Up @@ -164,3 +160,22 @@ func onterm(callback func()) {
<-sigchan
callback()
}

func getSecret() []byte {
secretFile := path.Join(config.DataDir(), "jwt-secret")
data, err := os.ReadFile(secretFile)
if err == nil {
zap.L().Debug("Loaded auth secret from file")
return data
}

zap.L().Info("Generating new auth secret")
secret := make([]byte, 64)
if n, err := rand.Read(secret); err != nil || n != 64 {
zap.S().Fatalf("Error generating secret: %v", err)
}
if err := os.WriteFile(secretFile, secret, 0600); err != nil {
zap.S().Fatalf("Error writing secret to file: %v", err)
}
return secret
}
9 changes: 6 additions & 3 deletions webui/src/components/OperationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
displayTypeToString,
getOperations,
getTypeForDisplay,
shouldHideOperation,
subscribeToOperations,
unsubscribeFromOperations,
} from "../state/oplog";
Expand All @@ -56,10 +55,12 @@ export const OperationList = ({
req,
useBackups,
showPlan,
filter,
}: React.PropsWithoutRef<{
req?: GetOperationsRequest;
useBackups?: BackupInfo[];
showPlan?: boolean,
filter?: (op: Operation) => boolean,
}>) => {
const alertApi = useAlertApi();

Expand Down Expand Up @@ -122,11 +123,13 @@ export const OperationList = ({
);
}

const operations = backups.flatMap((b) => b.operations);
let operations = backups.flatMap((b) => b.operations);
if (filter) {
operations = operations.filter(filter);
}
operations.sort((a, b) => {
return Number(b.unixTimeStartMs - a.unixTimeStartMs)
});

return (
<List
itemLayout="horizontal"
Expand Down
3 changes: 2 additions & 1 deletion webui/src/components/OperationTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
displayTypeToString,
getOperations,
getTypeForDisplay,
shouldHideOperation,
subscribeToOperations,
unsubscribeFromOperations,
} from "../state/oplog";
Expand Down Expand Up @@ -266,7 +267,7 @@ const BackupView = ({ backup }: { backup?: BackupInfo }) => {
} else {
return <>
<h3>Backup on {formatTime(backup.displayTime)}</h3>
<OperationList key={backup.id} useBackups={[backup]} />
<OperationList key={backup.id} useBackups={[backup]} filter={(op) => op && !shouldHideOperation(op)} />
</>;
}
}

0 comments on commit 427792c

Please sign in to comment.