Skip to content

Add anonymous access prompt during setup#583

Open
mccahan wants to merge 7 commits intojasonacox:mainfrom
mccahan:feature/anonymous-access
Open

Add anonymous access prompt during setup#583
mccahan wants to merge 7 commits intojasonacox:mainfrom
mccahan:feature/anonymous-access

Conversation

@mccahan
Copy link
Copy Markdown

@mccahan mccahan commented Feb 15, 2025

I saw settings for allowing anonymous access in the Grafana env sample, but figured it might be helpful to surface it as a question during the setup process.

image

@mccahan mccahan mentioned this pull request Feb 15, 2025
@jasonacox
Copy link
Copy Markdown
Owner

Thanks @mccahan - I like the idea. However, if we make this a separate workflow (anonymous-access.sh) it gives the impression that it is a standalone script. I think that is what we want, but currently the script pays no attention to the existing grafana.env file. Additionally, the way that the conditional works in setup.sh, it means that it will only run the first time you install. Ideally we want people to be able to run setup.sh to modify their configuration.

Can we add logic to edit the grafana.env instead of just append? I think it could be as simple as sed removing the relevant lines and then appending them back, as you have now.

@mccahan
Copy link
Copy Markdown
Author

mccahan commented Feb 16, 2025

@jasonacox good thoughts

  • Made it run every time they run setup.sh
  • Removes config lines (and double-checks the built-ins are commented out as appropriate) before appending when they change modes

@jasonacox
Copy link
Copy Markdown
Owner

I really like this addition / feature. Most of us run these dashboard for our private networks. Unless I'm wrong, in the worse case, the only thing a person could damage would be your customization of your dashboard.

I do want to see if we can make this simpler, and cover a few more use cases. Instead of two questions, we could minimize it to a condensed single question with a default:

Select Dashboard Access Method

  1. Username / Password [Default]
  2. Anonymous Read-Only
  3. Anonymous Read/Write

Enter your selection (or select 1 if you don't know) [current = 1]:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an interactive prompt during the setup process to configure anonymous access to Grafana dashboards. Previously, these settings existed only as commented lines in the grafana.env.sample file, requiring manual configuration.

Key changes:

  • New interactive script to configure anonymous access with read-only or read-write options
  • Integration of the anonymous access prompt into the main setup workflow
  • Fix for broken documentation anchor link

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
anonymous-access.sh New script that prompts users to enable anonymous access and configures Grafana environment settings accordingly
setup.sh Integrates the anonymous-access.sh script into the setup workflow after creating the Grafana environment file
README.md Fixes broken anchor link to the Grafana Setup section

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread anonymous-access.sh
;;
*)
remove_existing_settings
read_only_anonymous
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the default/fallback case (when user enters an invalid option), the script enables read-only anonymous access without providing any feedback to the user. This is inconsistent with the other cases which all provide confirmation messages. Users should be informed that their invalid input defaulted to read-only access.

Suggested change
read_only_anonymous
read_only_anonymous
# Feedback for invalid or empty selection
echo ""
echo "Invalid selection. Defaulting to anonymous read-only access."

Copilot uses AI. Check for mistakes.
Comment thread anonymous-access.sh Outdated
Comment thread setup.sh
Comment on lines +435 to 440
echo ""
./anonymous-access.sh
echo "-----------------------------------------"
echo ""

echo ""
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is being executed without checking if it exists or is executable. If the file is missing or lacks execute permissions, the setup will fail. Consider adding existence and error checking, or make the script executable during setup, similar to how other scripts in the repository handle execution.

Suggested change
echo ""
./anonymous-access.sh
echo "-----------------------------------------"
echo ""
echo ""
echo ""
if [ ! -x "./anonymous-access.sh" ]; then
if [ -f "./anonymous-access.sh" ]; then
echo "Making anonymous-access.sh executable..."
chmod +x "./anonymous-access.sh"
else
echo "ERROR: anonymous-access.sh not found. Cannot configure anonymous access."
exit 1
fi
fi
./anonymous-access.sh
echo "-----------------------------------------"
echo ""
echo ""
if [ ! -x "./tz.sh" ]; then
if [ -f "./tz.sh" ]; then
echo "Making tz.sh executable..."
chmod +x "./tz.sh"
else
echo "ERROR: tz.sh not found. Cannot configure timezone."
exit 1
fi
fi

Copilot uses AI. Check for mistakes.
Comment thread anonymous-access.sh Outdated
Comment thread anonymous-access.sh Outdated
Comment on lines +31 to +44
sed -i.bak '/^# Read-Only Anonymous Access/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_FEATURE_TOGGLES_PUBLICDASHBOARDS/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ENABLED/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' "${GF_ENV_FILE}"
rm -f "${GF_ENV_FILE}.bak"
fi
if grep -q "^GF_AUTH_DISABLE_LOGIN_FORM" "${GF_ENV_FILE}"; then
sed -i.bak '/^# Read-Write Anonymous Access/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_DISABLE_LOGIN_FORM/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ENABLED/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_USERS_ALLOW_SIGN_UP/d' "${GF_ENV_FILE}"
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple sequential sed operations with separate backup files is inefficient and could fail if a previous sed operation errors but the backup file is already created. Each sed creates a new .bak file that overwrites the previous one. Consider consolidating the sed operations into a single command with multiple -e expressions, or use a single backup creation followed by in-place edits without creating multiple backups.

Suggested change
sed -i.bak '/^# Read-Only Anonymous Access/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_FEATURE_TOGGLES_PUBLICDASHBOARDS/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ENABLED/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' "${GF_ENV_FILE}"
rm -f "${GF_ENV_FILE}.bak"
fi
if grep -q "^GF_AUTH_DISABLE_LOGIN_FORM" "${GF_ENV_FILE}"; then
sed -i.bak '/^# Read-Write Anonymous Access/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_DISABLE_LOGIN_FORM/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ENABLED/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' "${GF_ENV_FILE}"
sed -i.bak '/^GF_USERS_ALLOW_SIGN_UP/d' "${GF_ENV_FILE}"
sed -i.bak \
-e '/^# Read-Only Anonymous Access/d' \
-e '/^GF_FEATURE_TOGGLES_PUBLICDASHBOARDS/d' \
-e '/^GF_AUTH_ANONYMOUS_ENABLED/d' \
-e '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' \
-e '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' \
"${GF_ENV_FILE}"
rm -f "${GF_ENV_FILE}.bak"
fi
if grep -q "^GF_AUTH_DISABLE_LOGIN_FORM" "${GF_ENV_FILE}"; then
sed -i.bak \
-e '/^# Read-Write Anonymous Access/d' \
-e '/^GF_AUTH_DISABLE_LOGIN_FORM/d' \
-e '/^GF_AUTH_ANONYMOUS_ENABLED/d' \
-e '/^GF_AUTH_ANONYMOUS_ORG_NAME/d' \
-e '/^GF_AUTH_ANONYMOUS_ORG_ROLE/d' \
-e '/^GF_USERS_ALLOW_SIGN_UP/d' \
"${GF_ENV_FILE}"

Copilot uses AI. Check for mistakes.
Comment thread anonymous-access.sh
rm -f "${GF_ENV_FILE}.bak"
fi

sed -i.bak 's/^GF_AUTH_ANONYMOUS/#GF_AUTH_ANONYMOUS/' "${GF_ENV_FILE}"
Copy link

Copilot AI Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sed command at line 48 will comment out any line starting with GF_AUTH_ANONYMOUS, but this runs regardless of whether any matching lines exist. This could modify unrelated GF_AUTH_ANONYMOUS settings that aren't part of the anonymous access configuration being managed here. Consider being more specific about which settings to comment out, or check if the lines exist before modifying them.

Suggested change
sed -i.bak 's/^GF_AUTH_ANONYMOUS/#GF_AUTH_ANONYMOUS/' "${GF_ENV_FILE}"
if grep -qE '^GF_AUTH_ANONYMOUS_(ENABLED|ORG_NAME|ORG_ROLE)' "${GF_ENV_FILE}"; then
sed -i.bak -E 's/^(GF_AUTH_ANONYMOUS_(ENABLED|ORG_NAME|ORG_ROLE))/#\1/' "${GF_ENV_FILE}"
fi

Copilot uses AI. Check for mistakes.
Comment thread anonymous-access.sh
mccahan and others added 2 commits December 31, 2025 15:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants