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

Unexpected timestamp for meshagents #3281

Closed
tdobes opened this issue Nov 15, 2021 · 6 comments
Closed

Unexpected timestamp for meshagents #3281

tdobes opened this issue Nov 15, 2021 · 6 comments

Comments

@tdobes
Copy link

tdobes commented Nov 15, 2021

This is a change in behavior between MeshCentral 0.8.57 and 0.8.58 (and all newer versions).

In older versions, the file timestamp of meshagents reflected their approximate release time, so it could be used to determine their relative age. This timestamp could be used for caching and comparison during deployment, for example.

In versions 0.8.58 and newer, it appears that file timestamps are instead being set to a default from "npm pack". (See: npm/npm#19968 ) Specifically, when pulling the agents, I'm seeing "Last-Modified: Sat, 26 Oct 1985 08:15:00 GMT" regardless of the agent version.

Would it be possible to ensure that meshcentral serves the agents using a timestamp representing their (at least approximate) time of release? Sending out the release time of the meshcentral npm package might be an easy substitute, for example.

@Ylianst Ylianst self-assigned this Nov 15, 2021
@Ylianst
Copy link
Owner

Ylianst commented Nov 15, 2021

It looks like v0.8.58 is when I started using a new version of NPM to package MeshCentral, and so, the new NPM package behavior is now in effect.

The best way to get the MeshAgent version is to run it with -v for example:

image

It indicates exactly what version it is. An alternative is to look at node_modules/meshcentral/agents/hashagents.txt. This file contains all of the agent executable hashes. It can be used to compare with the agents you are currently using.

I am not sure how I would push the date or the agent into the npm pack, if you have a suggestion, let me know... but it would be best to use hashagents.txt if possible since that is not going to depend NPM behaving correctly.

@tdobes
Copy link
Author

tdobes commented Nov 16, 2021

Unfortunately, the place where this problem is effecting me is in caching/managing the meshagent updates externally. (This is on a system elsewhere in our infrastructure which handles deployment of meshagents to clients.) As a result, running meshagent binaries to determine their version isn't practical since most of the architectures won't execute natively. (For example, I can't determine version of the Windows build of MeshAgent from Linux.)

My recommendation (which is perhaps a bit naive) would be to adjust the HTTP Last-Modified header so that a reasonable date is sent out by MeshCentral. The on-disk files will still have the (bogus) date set by NPM, but at least the HTTP responses from MeshCentral can supply a meaningful date to clients. Perhaps this timestamp information could live in hashagents.txt since that file is already updated with each agent update?

For now, I've been hacking around this by tweaking the timestamps of the files myself after each invocation of npm:
touch -d `npm -g view meshcentral time.modified` /usr/local/lib/node_modules/meshcentral/agents/*
I haven't dug deeply into the code, but I don't see an obvious way to override this behavior of npm.

@Ylianst
Copy link
Owner

Ylianst commented Nov 16, 2021

Ha! I get it now. Changing the date/time of the HTTP response is something much more under my control.

@Ylianst
Copy link
Owner

Ylianst commented Nov 19, 2021

In next version of MeshCentral v0.9.52, the Last-Modified will now be set correctly when downloading a MeshAgent. The date and time of each agent comes from a new hashagents.json file in the agents folder. I used to have this as a text file, but changed it to JSON and added the agent creation date time in it.

image

Once released, let me know if that works.

FYI. In the screen above, I use the /meshagents page, you can access it on your server. It's a quick way to see all compiled binary agents and download links.

@Ylianst
Copy link
Owner

Ylianst commented Nov 26, 2021

Can you confirm this works? If it does, please close this issue. - Thanks.

@Ylianst
Copy link
Owner

Ylianst commented Nov 28, 2021

No replay. I will assume this worked. Closing.

@Ylianst Ylianst closed this as completed Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants