Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index out of range exception for the SSH Public Key page after deletion of auth source #31730

Closed
zyclonite opened this issue Jul 29, 2024 · 1 comment · Fixed by #31829
Closed
Labels
Milestone

Comments

@zyclonite
Copy link
Contributor

Description

If you have one ldap auth source and have ssh public key synchronisation in use. Keys in the database table get inserted with the login_source reference. When deleting an auth source gitea checks for references in the user table still using it but it does not check the public keys table still referencing it.
So after successfully deleting the auth source, having an old synchronised key will break the page for the particular user with the following exception.

PANIC: runtime error: index out of range [0] with length 0
/usr/local/go/src/runtime/panic.go:770 (0x43f2d3)
/go/src/code.gitea.io/gitea/modules/web/routing/logger_manager.go:116 (0x1ae84ab)
/usr/local/go/src/runtime/panic.go:770 (0x43f2d3)
/usr/local/go/src/runtime/panic.go:114 (0x43de1b)
/go/src/code.gitea.io/gitea/models/asymkey/ssh_key.go:257 (0x12c7adf)
/go/src/code.gitea.io/gitea/routers/web/user/setting/keys.go:299 (0x2418727)
/go/src/code.gitea.io/gitea/routers/web/user/setting/keys.go:34 (0x241598f)
/usr/local/go/src/reflect/value.go:596 (0x4fc75f)
/usr/local/go/src/reflect/value.go:380 (0x4fbc03)
/go/src/code.gitea.io/gitea/modules/web/handler.go:172 (0x1af1427)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/chain.go:31 (0x1ae8f7f)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:459 (0x1aebcc7)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/middleware/get_head.go:37 (0x234dc0b)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:182 (0x1af1497)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/services/context/context.go:225 (0x1bbfc93)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/gitea.com/go-chi/session@v0.0.0-20240316035857-16768d98ec96/session.go:257 (0x1a99c63)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:73 (0x1ae9ad3)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:327 (0x1aeb31f)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:459 (0x1aebcc7)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:73 (0x1ae9ad3)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:327 (0x1aeb31f)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:459 (0x1aebcc7)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/routing/logger_manager.go:122 (0x1ae8347)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/chi-middleware/proxy@v1.1.1/middleware.go:37 (0x2297957)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/routers/common/middleware.go:49 (0x2298abb)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/routers/common/middleware.go:40 (0x22986d3)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/routers/common/middleware.go:103 (0x2297c8b)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/src/code.gitea.io/gitea/modules/web/handler.go:136 (0x1af1867)
/usr/local/go/src/net/http/server.go:2171 (0x97a507)
/go/pkg/mod/github.com/go-chi/chi/v5@v5.0.12/mux.go:90 (0x1ae9a8f)
/go/src/code.gitea.io/gitea/modules/web/route.go:163 (0x1af2b9f)
/usr/local/go/src/net/http/server.go:3142 (0x97d91b)
/usr/local/go/src/net/http/server.go:2044 (0x9790d7)
/usr/local/go/src/runtime/asm_arm64.s:1222 (0x47c983)

Gitea Version

1.22.1

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

2.45.2

Operating System

CoreOS 40.20240701.3.0

How are you running Gitea?

containerized via podman (crun)

Database

MySQL/MariaDB

@zyclonite
Copy link
Contributor Author

might be similar to this error but it seems it got closed before deeper analysis #26959

potential solution might be checking for ssh keys upon auth source deletion or making the loop in ssh_key.go:257 not breaking

@lunny lunny added this to the 1.22.2 milestone Aug 2, 2024
@lunny lunny closed this as completed in b491b21 Aug 15, 2024
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Aug 15, 2024
…tea#31829)

Fix go-gitea#31730 

This PR rewrote the function `PublicKeysAreExternallyManaged` with a
simple test. The new function removed the loop to make it more readable.
lunny added a commit that referenced this issue Aug 15, 2024
… (#31836)

Backport #31829 by @lunny

Fix #31730 

This PR rewrote the function `PublicKeysAreExternallyManaged` with a
simple test. The new function removed the loop to make it more readable.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Nov 13, 2024
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
…tea#31829) (go-gitea#31836)

Backport go-gitea#31829 by @lunny

Fix go-gitea#31730

This PR rewrote the function `PublicKeysAreExternallyManaged` with a
simple test. The new function removed the loop to make it more readable.

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
(cherry picked from commit 5fa90ad)
project-mirrors-bot-tu bot pushed a commit to project-mirrors/forgejo-as-gitea-fork that referenced this issue Jan 23, 2025
…tea#31829)

Fix go-gitea#31730

This PR rewrote the function `PublicKeysAreExternallyManaged` with a
simple test. The new function removed the loop to make it more readable.

(cherry picked from commit b491b21)
(cherry picked from commit d550042)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants